apache 服務虛擬主機配置
上一篇部落格中,Apache服務已經成功安裝,配置,啟動成功。
現在對配置檔案 進行進一步配置:1.配置檔案路徑:E:/Apache/Apache24/conf/httpd.conf
1.埠配置
修改59行:(不同版本 行號可能不一樣),這裡預設的是80埠,埠可以配置多個
#Listen 12.34.56.78:80 Listen 80
2.根目錄配置:
修改250行:(不同版本 行號可能不一樣)
如下是預設配置(Apache服務啟動成功後,輸入網頁地址輸入:localhost ,顯示的it works 即是來自E:\Apache\Apache24\htdocs\ index.html)
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs"> Options Indexes FollowSymLinks //目錄下面沒有index檔案的時候 顯示目錄 AllowOverride None //是否允許覆蓋配置 Require all granted //訪問許可權配置 </Directory>
3.預設文件配置(index.html)
當在頁面輸入目錄路徑而不是具體的檔案路徑的時候,預設訪問index.html. 其配置如下(279行);
# # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html </IfModule>
4.虛擬主機配置:解註釋
1.目錄許可權配置(233行):
<Directory /> AllowOverride none
# 開啟所有配置的資料夾的訪問許可權 Require all granted </Directory>
2.解註釋虛擬主機配置檔案(509行)
# Virtual hosts Include conf/extra/httpd-vhosts.conf
此時,在cmd視窗執行如下命令:
E:\Apache\Apache24\bin>httpd -t AH00112: Warning: DocumentRoot [E:/Apache/Apache24/docs/dummy-host.example.com] does not exist AH00112: Warning: DocumentRoot [E:/Apache/Apache24/docs/dummy-host2.example.com] does not exist Syntax OK E:\Apache\Apache24\bin>
命令過程如上:
顯示兩處路徑不存在,這是因為剛剛解註釋了 Include conf/extra/httpd-vhosts.conf。
開啟apache根目錄下的: conf/extra/httpd-vhosts.conf
nclude conf/extra/httpd-vhosts.conf配置檔案中預設配置了兩個虛擬主機:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.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 [email protected]
DocumentRoot "${SRVROOT}/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>
修改conf/extra/httpd-vhosts.conf後:
# * 監聽繫結在當前電腦上任意IP的80埠
<VirtualHost *:80>
# 網站根目錄
DocumentRoot "E:\webProject\baixiu"
# 主機名字
ServerName baixiu.abb
ErrorLog "logs/baixiu-err.log"
CustomLog "logs/baixiu.log" common
</VirtualHost>
因為 baixiu.abb 域名沒有被申請,故為了測試虛擬主機是否配置成功,在hosts檔案末尾 增加127.0.0.1 baixiu.abb
5.測試
在瀏覽器中輸入baixiu.abb 成功打開了E:\webProject\baixiu 目錄下的index.html 檔案 ,表示虛擬主機配置成功