因為 Apache 的 Virtual Host 預設必須要放在 DocumentRoot 的目錄底下,否則會出現 client denied by server configuration
必須在 Virtual Host 的 conf 加上以下幾行
Apache 2.2 版
wbkuo 發表在 痞客邦 留言(0) 人氣(197)
在 AWS EC2 裝好基本的 LAMP 環境之後,想設一下 Apache Virtual Host 設定
結果居然無法運作,查了一下才發現在 Apache 2.4.6 (或更之前) 有對這部份的設定做了一些調整
以下是簡易的筆記
1. NameVirtualHost*:80 這行已經廢除,不用再寫了
2. 原本的 http.conf 已經預設加上 IncludeOptional conf.d/*.conf
所以可以把 Virtual Host 的設定獨立成另一隻檔案,我習慣命名為 vhosts.conf,放在 /etc/httpd/conf.d/vhosts.conf
3. <VirtualHost> 的調整
由原本的
<VirtualHost sample.com>
DocumentRoot /var/www/www_sample
ServerName sample.com
CustomLog logs/access_log combined
DirectoryIndex index.php index.html index.htm index.shtml
<Directory "/var/www/www_sample">
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
改為
<VirtualHost *:80>
DocumentRoot /var/www/www_sample
ServerName sample.com
CustomLog logs/access_log combined
DirectoryIndex index.php index.html index.htm index.shtml
<Directory "/var/www/www_sample">
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
domain name 不用再重覆寫兩遍了!!
請參考:http://stackoverflow.com/questions/25608659/virtualhost-is-not-working-under-apache-2-4-6-on-centos-7
wbkuo 發表在 痞客邦 留言(1) 人氣(8,591)
請參考:http://linux.vbird.org/linux_server/0360apache.php#www_basic_basic
--
使用情境
假設我要在 http://localhost/phpMyAdmin 裡放 phpMyAdmin 的服務
但 phpMyAdmin 目錄我想不放在我網站的目錄,那麼可以這樣設定
<VirtualHost localhost>
DocumentRoot /var/www/html
ServerName localhost
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
</Directory>
# 把 phpMyAdmin 用 Alias 的方式設定進來
Alias /phpMyAdmin/ "/var/www/phpMyAdmin/"
<Directory "/var/www/phpMyAdmin">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
wbkuo 發表在 痞客邦 留言(0) 人氣(611)
1. 修改 httpd.conf,新增 Listen
在原本 Listen 80 後加上想要使用的 Port
Listen 8012
2. 修改 httpd-vhosts.conf,加上想要的站
<VirtualHost *:8012>
DocumentRoot "D:\www\www_8012"
ServerName localhost:8012
<Directory "D:\www\www_8012">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
3. 重新啟動 apache
4. 輸入 http://localhost:8012 測試看看
註1:以上範例是以 Xampp 3.2.1 為準
註2:其實是因為公司內部控管比較嚴,沒有辦法修改 hosts 的關係
wbkuo 發表在 痞客邦 留言(1) 人氣(3,663)
1. 修改 hosts
路徑 C:\Windows\System32\drivers\etc\hosts,加上
127.0.0.1 test.local
2. 修改 httpd-vhosts.conf
路徑 C:\xampp\apache\conf\extra\httpd-vhosts.conf 加上
NameVirtualHost *
<VirtualHost *>
DocumentRoot "D:\www\www_test"
ServerName test.local
<Directory "D:\www\www_test">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
註:以上是 apache 2.4 的設定方法,如果是 apache 2.2 的話請把 <Director> 改為
<Directory "D:\www\www_test">
Order allow,deny
Allow from all
</Directory>
3. 重新啟動 apache
wbkuo 發表在 痞客邦 留言(0) 人氣(1,304)
查了好久才發現,原來 appserv 安裝的 apache 預設是把 rewrite_module 註解掉的
所以把底下這行解除註解就可以了
LoadModule rewrite_module modules/mod_rewrite.so
wbkuo 發表在 痞客邦 留言(0) 人氣(233)