XAMPP 虚拟主机提供了错误的文档根目录
XAMPP with virtualhost is serving the wrong documentroot
我 运行 xampp 在 Linux 并且想要设置虚拟主机,这样我可以在项目之间快速跳转。
我有两个这样设置的项目:
/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 webmaster@webdev.app1
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 webmaster@webdev.app2
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.app1
或 webdev.app2
时,它提供常规 htdocs
文件夹而不是修改后的 DocumentRoot
。当我去 localhost
时,它提供在 httpd-vhost.conf
中首先命名的任何内容,在本例中为 /home/(user)/webdev/app1
.
我期望的行为是当我访问 webdev.app1 时提供 app1,而当我访问 webdev.app2 时提供 app2。我错过了什么?
您的虚拟主机设置不正确,您是在告诉 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----------------
我 运行 xampp 在 Linux 并且想要设置虚拟主机,这样我可以在项目之间快速跳转。
我有两个这样设置的项目:
/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 webmaster@webdev.app1
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 webmaster@webdev.app2
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.app1
或 webdev.app2
时,它提供常规 htdocs
文件夹而不是修改后的 DocumentRoot
。当我去 localhost
时,它提供在 httpd-vhost.conf
中首先命名的任何内容,在本例中为 /home/(user)/webdev/app1
.
我期望的行为是当我访问 webdev.app1 时提供 app1,而当我访问 webdev.app2 时提供 app2。我错过了什么?
您的虚拟主机设置不正确,您是在告诉 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----------------