Apache 作为所有文件的代理

Apache 作为所有文件的代理

我正在尝试配置 apache 以充当某些子域的代理。我几乎已经配置好了,但有一个问题。

通过此配置,我已成功使 www.mywebsite.com 正常提供服务(无代理/默认 apache 配置),同时通过代理将 subdomain.mywebsite.com 服务于本地主机端口 8080。我遇到的问题是,对 index.html 以外的文件的请求会出现代理错误 502。

ServerAdmin [email protected]
ServerName subdomain.mywebsite.com

DocumentRoot "/opt/www/subdomain"

<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>

ProxyPass / http://127.0.0.1:8080
ProxyPassReverse / http://127.0.0.1:8080

我如何配置 apache 来通过代理提供所有文件?

答案1

我不太明白你发布的内容是如何实现你想要的。但我对这个问题的理解可能是错误的。我知道你想要:

  1. www.mywebsite.com 从“/opt/www/subdomain”提供页面
  2. subdomain.mywebsite.com 从运行在端口 8080 上的后端服务器提供页面。

因此你只需要这个:

<VirtualHost *:80>
  DocumentRoot "/opt/www/subdomain"
  ServerName www.mywebsite.com
</VirtualHost>
<VirtualHost *:80>
  ServerName subdomain.mywebsite.com
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080
</VirtualHost>

ProxyPass 行与您所拥有的一个区别是,我有一个尾随斜杠来匹配指令的右侧。

相关内容