同时使用 Apache 反向代理和虚拟主机

Apache Reverse Proxy and Virtual Host at the Same Time

我有一个 VPS,只有一个 IP。 VPS 应该服务于 3 个网站。 Site1 - www.domain.com 通过 WordPress。 Site2 - sub.domain.com 通过 WordPress。 Site3 - 另一个sub.domain.com 通过Docker 容器内的NodeJS 侦听端口81。Site1 和Site2 非常简单,只需要设置虚拟主机。但是,如何为 Site3 设置 Apache?您能否提供示例或正确的语法?

来自 apache 文档 (https://httpd.apache.org/docs/current/vhosts/examples.html#proxy)

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass        "/" "http://192.168.111.2/"
    ProxyPassReverse "/" "http://192.168.111.2/"
    ServerName hostname.example.com
</VirtualHost>

对于你的情况:

  <VirtualHost *:80>
        ProxyPreserveHost On
        ProxyPass        "/" "http://localhost:81/"
        ProxyPassReverse "/" "http://localhost:81/"
        ServerName hostname.example.com
    </VirtualHost>

祝你好运!