window系統下 Apache配置虛擬主機和虛擬目錄的方法
阿新 • • 發佈:2019-01-05
Apache配置虛擬主機
1.方式一:使用不同的服務埠,啟動多個apache服務例項,使用各自的配置檔案
1)配置檔案中新增監聽的埠
Listen801
Listen802
2)
<VirtualHost*:801>
[email protected]
DocumentRoot"E:/webserver/www/thinkphp"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/thinkphp">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
[email protected]
DocumentRoot"E:/webserver/www/learnlaravel5"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/learnlaravel5">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
3)重啟伺服器
2.方式二:同一個埠,配置多個虛擬主機
一、配置HOST檔案
首先在你的系統盤下windows/system32/drivers/etc/host
二、修改httpd.conf
需要開啟httpd.conf的LoadModulerewrite_modulemodules/mod_rewrite.so
去掉Includeconf/extra/httpd-vhosts.conf前的#註釋
三、配置httpd-vhosts.conf
NameVirtualHost127.0.0.1:80
<VirtualHostweb.shops.com:80>
DocumentRoot"D:\AppServ\www\shops"
ServerNameweb.shops.com
<Directory"D:\AppServ\www\shops">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
*訪問虛擬主機如果出現
Forbidden You don't have permission to access/onthisserver錯誤
這是因為新建的虛擬主機的目錄沒有讀許可權。做如下操作:
1.把相應目錄的許可權改為可讀。
2.在虛擬主機配置後面新增如下程式碼
<Directory"D:/Web">
OptionsFollowSymLinks
AllowOverrideNone
Orderdeny,allow
Allowfromall
</Directory>
Apache配置虛擬目錄
編輯httpd.conf檔案,增加
Alias/xx“實際目錄路徑”
和上面虛擬主機的配置一樣,下面也需要加目錄許可權配置<Directory>,否則也不能訪問。
1.方式一:使用不同的服務埠,啟動多個apache服務例項,使用各自的配置檔案
1)配置檔案中新增監聽的埠
Listen801
Listen802
2)
<VirtualHost*:801>
[email protected]
DocumentRoot"E:/webserver/www/thinkphp"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/thinkphp">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
<VirtualHost*:802>[email protected]
DocumentRoot"E:/webserver/www/learnlaravel5"
ServerNamewww
ServerAliaslocalhost
<Directory"E:/webserver/www/learnlaravel5">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
3)重啟伺服器
2.方式二:同一個埠,配置多個虛擬主機
一、配置HOST檔案
首先在你的系統盤下windows/system32/drivers/etc/host
二、修改httpd.conf
需要開啟httpd.conf的LoadModulerewrite_modulemodules/mod_rewrite.so
去掉Includeconf/extra/httpd-vhosts.conf前的#註釋
三、配置httpd-vhosts.conf
NameVirtualHost127.0.0.1:80
<VirtualHostweb.shops.com:80>
DocumentRoot"D:\AppServ\www\shops"
ServerNameweb.shops.com
<Directory"D:\AppServ\www\shops">
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allowfromall
</Directory>
</VirtualHost>
Forbidden You don't have permission to access/onthisserver錯誤
這是因為新建的虛擬主機的目錄沒有讀許可權。做如下操作:
1.把相應目錄的許可權改為可讀。
2.在虛擬主機配置後面新增如下程式碼
<Directory"D:/Web">
OptionsFollowSymLinks
AllowOverrideNone
Orderdeny,allow
Allowfromall
</Directory>
Apache配置虛擬目錄
編輯httpd.conf檔案,增加
Alias/xx“實際目錄路徑”
和上面虛擬主機的配置一樣,下面也需要加目錄許可權配置<Directory>,否則也不能訪問。