apache中多域名使用同一个ip的方法

服务器仅有一个ip ,却需要服务多个域名(实际是多个网站的服务),例如你希望使用同一个台web服务器上同时运行www.example.com与www.example.net。 可在httpd.conf配置文件中(可能位于/etc/httpd/conf或/usr/local/apache/conf目录下),添加以下条目:

Server configuration

# Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/example1 ServerName www.example.com # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/example2 ServerName www.example.org # Other directives here </VirtualHost> apache会就用户访问的域名对应配置中的ServerName选择合适的web目录输出html代码。以上设置中第一项即ServerName www.example.com成为默认选项。若用户访问所指定的域名不符合所有条目时采用默认项,即指向www.example.com。 apache官方的文档: http://httpd.apache.org/docs/2.2/vhosts/examples.html
原文地址:https://www.cnblogs.com/macleanoracle/p/2967300.html