原来配置文件放到了conf/extra/下面,使得httpd.conf更加简洁了。
conf/extra/httpd-vhosts.conf
1、打开httpd.conf: 将#Include conf/extra/httpd-vhosts.conf 前的“#”去掉 让apache加载虚拟机配置文件
2、打开conf/extra/httpd-vhosts.conf,隐掉或删掉例子
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot "/usr/local/apache2/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
3、 #ip指向web可访问目录
<VirtualHost *:80>
ServerAdmin email@email.com
DocumentRoot "/opt/web/root/"
ServerName 123.456.789.123
</VirtualHost>
#域名指向web可访问目录下的某一个项目
<VirtualHost *:80>
ServerAdmin email@email.com
DocumentRoot "/opt/web/root/test/"
ServerName www.test.com
</VirtualHost>
4、重启apache
http://123.456.789.123/test 与 http://www.test.com 都可以访问test项目。
/etc/hosts文件:配置好域名
192.168.155.2 www.test.com
内网ip 域名
======================================================================================
可能出现的问题,访问www.test.com报错:You don't have permission to access / on this server.
这时修改httpd.conf160行左右将Directory项修改为:
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>