NameVirtualHost *:80
注意一:NameVirtualHost 指定虚拟主机所使用的IP地址或域名,但是最好是IP地址。使用基于域名的虚拟主机时,NameVirtualHost是必要的指令。NameVirtualHost可以定义多个。
注意二:所有符合NameVirtualHost或
注意三:如果设置NameVirtualHost 或
比如我们以IP192.168.0.3配置两个虚拟主机。
首先编辑 /etc/httpd/conf/httpd.conf配置文件
vi /etc/httpd/conf/httpd.conf
然后添加如下代码至文件底部:
NameVirtualHost 192.168.0.3
ServerAdmin [email protected]
DocumentRoot /var/www/html/website2
ServerName www.website2.com
ErrorLog /var/www/html/website2/logs/error_log
TransferLog /var/www/html/website2/logs/access_log
ServerAdmin [email protected]
DocumentRoot /var/www/html/website3
ServerName www.website3.com
ErrorLog /var/www/html/website3/logs/error_log
TransferLog /var/www/html/website3/logs/access_log
如果你有多个IP,则继续按以上代码添加,只需要修改192.168.0.3成你的IP即可。
让服务器支持多个网站,针对Apache,只需要你修改apache配置文件/etc/httpd/conf/httpd.conf即可。
里面有个example文件,你只要对应配置即可。
#
# ServerAdmin [email protected]
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#
你可以参照我的配置,在httpd.conf最底部添加:
NameVirtualHost *:80
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName www.111com.net
#ErrorLog /var/log/httpd/phpddt/error_log
#注意,这里我设置了以天为单位生产日志
ErrorLog "|rotatelogs /var/log/httpd/phpddt/error_log%Y_%m_%d.log 86400 480"
#CustomLog /var/log/httpd/phpddt/access_log common
CustomLog "|rotatelogs /var/log/httpd/phpddt/access_log%Y_%m_%d.log 86400 480" common
ServerAdmin [email protected]
DocumentRoot /var/www/html/blog
ServerName m.111com.net
ErrorLog /var/log/httpd/blog/error_log
CustomLog /var/log/httpd/blog/access_log common
如上我配置了两台虚拟主机:域名分别为www.111com.net m.111com.net
注意,重启apache后才生效(service httpd restart)