Apache 作为多个目的地和一个默认目的地的反向代理

kob*_*ame 9 apache-http-server reverse-proxy

为下一个 Apache 的reverse-proxy问题寻求帮助。

  • 在 localhost:80 (aaaa:80) 上有一个 Apache 2.4
  • 有 3 个不同的 Web 应用程序
    • 一个在 localhost:8000 (aaaa:8000) 上运行
    • 另外两个在另一台机器上 - 所以 xxxx:8000 和 yyyy:8000
  • 在基本的 apache:80 上有一些静态内容(很少的 html 页面) DocumentRoot

要求

  • appX(在 xxxx:8000 上)应该通过http://aaaa/appX/ 访问
  • appY(在 yyyy:8000 上)为http://aaaa/appY/
  • 现有的静态页面(来自 apache 的DocumentRoot)应该像通常那样由 apache 提供服务
  • defapp-其他一切都应该代理到 aaaa:8000

很容易配置appXappY喜欢下一个:

ProxyPass         /appX/ http://x.x.x.x:8000/
ProxyPassReverse  /appX/ http://x.x.x.x:8000/

ProxyPass         /appY/ http://y.y.y.y:8000/
ProxyPassReverse  /appY/ http://y.y.y.y:8000/
Run Code Online (Sandbox Code Playgroud)

以上工作正常。因此,当试图访问http://localhost/appX/接到了一个响应appXx.x.x.x:8000

但是default destinatonfor有问题everything other。尝试添加时:

ProxyPass         /   http://127.0.0.1:8000/
ProxyPassReverse  /   http://127.0.0.1:8000/
Run Code Online (Sandbox Code Playgroud)

它不像我希望的那样工作......

有了上面的内容,想告诉 apache -其他不是/appX//appY/发送到的所有内容0:8000

这是遗憾的是不工作的,在defapp什么上运行0:8000了该请求appX,并appY,并为静态页面太请求。

切换定义的顺序,所以

#define first the "default destination"
ProxyPass         /   http://127.0.0.1:8000/
ProxyPassReverse  /   http://127.0.0.1:8000/

#and after the appX and appY
ProxyPass         /appX/ http://x.x.x.x:8000/
ProxyPassReverse  /appX/ http://x.x.x.x:8000/
ProxyPass         /appY/ http://y.y.y.y:8000/
ProxyPassReverse  /appY/ http://y.y.y.y:8000/
Run Code Online (Sandbox Code Playgroud)

也不起作用。一切都被代理到localhost:8000.

所以,问题是:是否可以将 Apache 配置为反向代理来处理上述定义的需求?

Nat*_*n C 6

将您的 ProxyPass 引用包装在一个<VirtualHost>定义中,如下所示:

<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://192.168.111.2/
ProxyPassReverse / http://192.168.111.2/
ServerName hostname.example.com
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

使用您想要的 ServerNames 创建两个单独的一个,然后另一个没有 ServerName 或定义的代理选项(只是DocumentRoot)。把那个放在最后。

更多信息在这里