我在 Linux 上運行 xampp 并想設定虛擬主機,這樣我就可以在專案之間快速跳轉。
我有兩個專案是這樣設定的:
/home/(user)/webdev/app1 其中包含一個 index.html
/home/(user)/webdev/app2 其中包含一個 index.html
我的httpd.conf包括這些片段:
<Directory "/home/(user)/webdev/app1">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>
<Directory "/home/(user)/webdev/app2">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>
并且Include etc/extra/httpd-vhosts.conf沒有注釋。
我的httpd-vhosts.conf包括這個:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/home/(user)/webdev/app1"
ServerName webdev.app1
ErrorLog "logs/app1.example.com-error_log"
CustomLog "logs/app1.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/home/(user)/webdev/app2"
ServerName webdev.app2
ErrorLog "logs/app2.example.com-error_log"
CustomLog "logs/app2.example.com-access_log" common
</VirtualHost>
我的/etc/hosts檔案如下所示:
127.0.0.1 localhost
::1 localhost
127.0.0.1 webdev.app1
127.0.0.1 webdev.app2
據我所知,我做的一切都是正確的。不幸的是,當我轉到webev.app1or 時webdev.app2,它提供常規htdocs檔案夾而不是修改后的DocumentRoot. 在這種情況下localhost,當我去時,它會提供第一個命名的任何內容。httpd-vhost.conf/home/(user)/webdev/app1
我期望的行為是當我訪問 webdev.app1 時提供 app1,而當我訪問 webdev.app2 時提供 app2。我錯過了什么?
uj5u.com熱心網友回復:
您的虛擬主機設定不正確,您告訴 Apache 如果有任何請求在埠 80 上服務 app1,同時如果有任何請求在埠 80 上服務 app2。使用以下示例之一修復它:
----------START DIFFERENTIATE VIA DIFFERENT DOMAINS----------------
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/app1"
ServerName www.app1.com
ServerAlias *.app1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/app2"
ServerName www.app2.com
ServerAlias *.app2.com
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA DIFFERENT DOMAINS----------------
----------START DIFFERENTIATE VIA SUB FOLDERS----------------
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/apps"
# in the 'apps' folder place subfolders 'app1' and 'app2'
# navigate in the browser to each app i.e. 127.0.0.1/apps/app1 and 127.0.0.1/apps/app2
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA SUB FOLDERS----------------
----------START DIFFERENTIATE VIA DIFFERENT PORTS----------------
Listen 81
Listen 82
<VirtualHost *:81>
DocumentRoot "/www/app1"
# Other directives here
</VirtualHost>
<VirtualHost *:82>
DocumentRoot "/www/app2"
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA DIFFERENT PORTS----------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/364292.html
