当一台服务器需要挂几个站点时,我们希望不同的域名指向不同的站点,这时就需要使用Apache VirtualHost,apache虚拟主机站点,并可设置相关的访问端口。
在/etc/httpd/cong/conf/httpd.conf配置
找到VirtualHost
去除下面的注释,填写相关的域名和域名指向的路径,路径域名需写对否则无法重启apache
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# 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
#</VirtualHost>
如果有更多的站点,直接在后面添加相关的配置即可
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
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
</VirtualHost>
完成配置后
service httpd restart 重启服务器