将虚拟主机 http 和 https 重定向到另一个虚拟主机服务器

Redirect a virtualhost http & https to another virtualhost server

我有 2 个 apache 2.4 serverA 和 serverB 以及几个虚拟主机。所有传入请求都到达服务器 A。

如何将对特定虚拟主机名的 http 和 https 请求从 serverA 转发到 serverB?

我的 wamp ServerA 设置是: 进入我的主机文件 127.0.0.7 example.com

虚拟主机:

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

我的serverB ip是192.168.1.105,我在上面设置了一个同名的虚拟主机example.com

当我使用 http://example.com 时,我会像 http://localhost 一样停留在 wamp 主页上 当我使用 https://example.com 时,serverA

出现错误 403(禁止访问)

在 ServerA 虚拟主机中添加一个简单的:

Redirect / https://serverb.examample.com/

熬夜,找到解决办法:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass         "/" "http://192.168.1.105/"
    ProxyPassReverse  "/" "http://192.168.1.105/"
    ServerName        example.com
</VirtualHost>
<VirtualHost *:443>
    SSLProxyEngine on
    SSLCertificateFile    "${APACHE_DIR}/conf/ssl_example.com/server.crt"
    SSLCertificateKeyFile "${APACHE_DIR}/conf/ssl_example.com/server.key"
    ErrorLog  "logs/example.com-ssl_error.log"
    CustomLog "logs/example.com-ssl_access.log" common
    ProxyPreserveHost On
    ProxyPass         "/" "https://192.168.1.105/"
    ProxyPassReverse  "/" "https://192.168.1.105/"
    ServerName        example.com
</VirtualHost>