Apache 在一个 VirtualHost 中有多个 ProxyPass 条目

DrK*_*liN 7 apache-http-server proxy

所以我有以下两种配置:

一方面是后端服务器:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost
  ProxyPass /backend http://some_remote_ip:7000/backend
  ProxyPassReverse /backend http://some_remote_ip:7000/backend
  ProxyPassReverseCookiePath / /backend
  ProxyPassReverseCookieDomain some_remote_ip localhost
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

另一方面是前端服务器:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost
  ProxyPass  /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

如果我将它们放在一个.conf文件中,则只有文件中第一个写入的文件才能工作,因此从技术上讲,它们都是正确的。

所以我的问题是如何在同一配置中有多个ProxyPass条目? VirtualHost

PS:我需要能够访问

  • 后端在 localhost/backend
  • 前端在 localhost

mta*_*tak 7

问题是对于同一个虚拟主机 ( localhost),您有多个 VirtualHost 部分,因此 Apache 只会选择一个。如果您希望这些配置一起工作,您必须将ProxyPass指令放在单个 VirtualHost 配置中:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost

  ProxyPass /backend http://some_remote_ip:7000/backend
  ProxyPassReverse /backend http://some_remote_ip:7000/backend
  ProxyPassReverseCookiePath / /backend
  ProxyPassReverseCookieDomain some_remote_ip localhost

  ProxyPass  /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)