在 Apache 中向反向代理添加异常

Adding exception to reverse proxy in Apache

我在 ubuntu 16.04 服务器机器上配置了一个应用程序 (jitsi-meet),通过 Apache 提供服务。应用程序的 DocumentRoot 位于 /usr/share/jitsi-meet 并且 Apache 配置已通过脚本自动安装应用程序进行处理。服务器有一个 FQDN,应用程序可以直接通过基础 url,比如 http://example.com 获得。我还通过 letsencrypt 安装了一个 SSL 证书,它也负责从 http 到 https 的重定向。

在 /etc/apache2/sites-available/example.com.conf looks like this.

可用的当前 Apache 配置
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
   RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>

  ServerName example.com

  SSLProtocol TLSv1 TLSv1.1 TLSv1.2
  SSLEngine on
  SSLProxyEngine on
  SSLCipherSuite "EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH$
  SSLHonorCipherOrder on
  Header set Strict-Transport-Security "max-age=31536000"

  DocumentRoot "/usr/share/jitsi-meet"
  <Directory "/usr/share/jitsi-meet">
    Options Indexes MultiViews Includes FollowSymLinks
    AddOutputFilter Includes html
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

      ErrorDocument 404 /static/404.html

Alias "/config.js" "/etc/jitsi/meet/example.com-config.js"
  <Location /config.js>
    Require all granted
  </Location>

    ProxyPreserveHost on
ProxyPass /http-bind http://localhost:5280/http-bind/
ProxyPassReverse /http-bind http://localhost:5280/http-bind/

    ProxyPreserveHost on
ProxyPass /forum http://192.168.1.5/forum
ProxyPassReverse /forum http://192.168.1.5/forum

  RewriteEngine on
  RewriteRule ^/([a-zA-Z0-9]+)$ /index.html
  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/example.com-0001/full$
SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0001/pri$
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

现在,我想做的是在我的 Apache 的反向代理配置中添加一个例外,以便 http://example.com/forum redirects to another website that is hosted on another machine in the same network, say, http://192.168.1.5/forum。 (编辑以在配置中添加信息 - 不起作用)

Apache 配置不是我的强项,因此您必须对我温柔点。我尝试简单地更改设置 /http-bind 反向代理的部分,将其重定向到我的论坛 url 并且它有点工作(没有脚本 运行)所以它给了我希望应该可以在不完全重新配置设置的情况下实现。

如果需要我提供任何其他信息,请告诉我。

干杯!

配置中有几处需要修改:

-删除 Alias /forum ... 行,它与您要实现的目标相矛盾

-为 /forum URI 添加 ProxyPass 指令:

ProxyPreserveHost on
ProxyPass /forum http://192.168.1.5/forum
ProxyPassReverse /forum http://192.168.1.5/forum

-确保您的重写规则(否则将重写任何请求到 /index.html)不会为 /forum 执行,方法是添加条件:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/forum
RewriteRule ^/([a-zA-Z0-9]+)$ /index.html

(/http-bind 工作正常,因为它不匹配正则表达式 [a-zA-Z0-9])