【发布时间】:2021-08-16 15:59:04
【问题描述】:
我正在尝试配置一个 Apache 服务器来处理多个虚拟主机并使用反向代理公开它们。
在我写的 httpd-vhosts 文件中:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName temp
DocumentRoot "c:/users/test/sites/testsite"
<Directory "c:/users/test/sites/testsite">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ProxyPreserveHost On
<Proxy>
Order deny,allow
Allow from all
</Proxy>
ProxyPass "temp:8080" "http://my.domain.com/"
ProxyPassReverse "temp:8080" "http://my.domain.com/"
</VirtualHost>
我希望当我通过“http://my.domain.com/”连接到我的服务器时,客户端连接到临时虚拟服务器,而当连接到“localhost”时,我仍然连接到 localhost 服务器. 但是这个配置不起作用。我可以在本地连接到 localhost 和“http://temp:8080”,但无法通过“http://my.domain.com/”连接。
如果我注释第一个 VirtualHost,并且我配置第二个监听端口 80,我可以使用“http://my.domain.com/”连接(但是这样反向代理是没用的:如果我省略了那部分,它仍然有效),但在本地我无法连接到“localhost”(显然)。
我该如何解决这个问题? 谢谢
【问题讨论】:
标签: apache reverse-proxy virtualhost