Apache 反向代理到 docker 容器

Jal*_*bal 8 reverse-proxy docker apache-2.4

我有一个在 docker 容器上运行的网站,并且我在主机的 apache 上创建了一个 VirtualHost,它对容器(在主机的 8280 端口上)执行反向代理。所以我有:

<VirtualHost *:443>
    ServerName www.example.com
    DirectoryIndex index.php index.html
    SetOutputFilter SUBSTITUTE,DEFLATE

    ProxyPass / http://localname:8280/
    ProxyPassReverse / http://localname:8280/

    Substitute "s|http://localname:8280/|https://www.example.com/|i"

    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateKeyFile /path-to/privkey.pem
    SSLCertificateFile /path-to/cert.pem
    SSLCertificateChainFile /path-to/chain.pem

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

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias www.example.com

    Redirect permanent / https://www.example.com/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

代理运行良好,我在浏览器中写入 www.example.com 时有响应,但我的所有链接都指向http://localname:8280(如浏览器控制台中所示)和混合内容错误,这就是为什么我已经放置了替代指令,但它不起作用。

我正在使用 apache 文档中 mod_substitute 的配置。

https://httpd.apache.org/docs/2.4/mod/mod_substitute.html

但这不起作用,任何变化。docker 容器基于默认配置的 bitnami/apache 镜像。

任何帮助,将不胜感激。

Jal*_*bal 3

好吧,我自己找到了答案。您只需在 Substitute 指令上添加以下行:

AddOutputFilterByType SUBSTITUTE text/html
Run Code Online (Sandbox Code Playgroud)