apache2.4配置虛擬主機
好幾年沒碰apache了,突然發現高版本的apache不會配置虛擬主機了。
原來配置檔案放到了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 [email protected]
# 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 protected]
DocumentRoot "/opt/web/root/"
ServerName 123.456.789.123
</VirtualHost>
#域名指向web可訪問目錄下的某一個專案
<VirtualHost *:80>
ServerAdmin [email protected]
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>