如何将 Apache 设置为 docker 容器的反向代理

use*_*950 2 nginx apache2

我努力将我的 Apache 服务器设置为包含Greenlight 的docker 的反向代理实例的 docker 的反向代理。

\n

在官方文档中,建议在 docker 容器中运行 Greenlight,并使用 Nginx 实例作为反向代理(主要是为了更容易与BBB 服务器一起运行)一起运行它)。\n但在我的设置中,我不想运行自己的 BBB实例,而是使用 Greenlight 作为外部 BBB 服务器的前端。

\n

但为了方便起见,我还是在 Docker 容器中设置了 Greenlight。

\n

但由于我的服务器有很多用途(主要是用于交付多个网站并提供由Froxlor管理的电子邮件帐户,但它也可以用作Matrix 服务器)我不想将 Nginx 设置为代理,因为那样会迫使我大幅改变我实际运行的 Froxlor 管理的 Apache 设置。

\n

所以我尝试将 Apache 配置为反向代理。不幸的是,文档中只有一个 Nginx 示例:

\n
location /b {\n  proxy_pass          http://127.0.0.1:5000;\n  proxy_set_header    Host              $host;\n  proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;\n  proxy_set_header    X-Forwarded-Proto $scheme;\n  proxy_http_version  1.1;\n}\n\nlocation /b/cable {\n  proxy_pass          http://127.0.0.1:5000;\n  proxy_set_header    Host              $host;\n  proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;\n  proxy_set_header    X-Forwarded-Proto $scheme;\n  proxy_set_header    Upgrade           $http_upgrade;\n  proxy_set_header    Connection        "Upgrade";\n  proxy_http_version  1.1;\n  proxy_read_timeout  6h;\n  proxy_send_timeout  6h;\n  client_body_timeout 6h;\n  send_timeout        6h;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我使用以下 VirtualHost 设置在 Apache 上进行这项工作:

\n
<VirtualHost MYIP:443>\n  ServerName greenlight.example.com\nProxyPreserveHost On\nProxyRequests Off\nProxyVia On\nProxyPass / http://127.0.0.1:5000\nProxyPassReverse / http://127.0.0.1:5000   \n<Location "/cable">\n  ProxyPass / http://127.0.0.1:5000 connectiontimeout=6h timeout=6h\n  ProxyPassReverse / http://127.0.0.1:5000\n</Location>\n</VirtualHost>\n
Run Code Online (Sandbox Code Playgroud)\n

我从示例中转移,我不想使用虚拟子文件夹 \xc2\xbbb\xc2\xab ,而是使用子域 t 将特定流量重定向到本地端口5000。不幸的是,这不起作用。\n服务器返回

\n
502 Prox error\n\nProxy Error\n\nThe proxy server received an invalid response from an upstream server.\nThe proxy server could not handle the request\n\nReason: Error reading from remote server\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以向我解释一下这个错误的原因是什么吗?如何将 Nginx 标头设置转换为 Apache 和其他超时设置,它们是否有必要?

\n

Ger*_*der 5

这里有几个问题:

  1. 顺序
    第一个匹配的路径获胜。您/之前放置过/cable,因此/将始终匹配并且/cable永远不会被使用。
  2. 匹配尾部斜杠
    如果第一个参数ProxyPass以 a结尾/,则需要在第二个参数上添加 1,反之亦然。否则,您最终会收到发送到后端的无效 URL
  3. <Location>块内的 ProxyPass
    如果您ProxyPass在 a 内使用<Location>,它只会获取第二个参数。第一个正在被<Location>.

例子:

<VirtualHost MYIP:443>
    ServerName greenlight.example.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia On
    ProxyPass /cable http://127.0.0.1:5000 connectiontimeout=6h timeout=6h
    ProxyPassReverse /cable http://127.0.0.1:5000
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

最后但并非最不重要的一点是,当前您将两个位置代理到同一后端 URL。这通常是错误的。