【问题标题】:Apache reverse proxy subdomain to portApache 反向代理子域到端口
【发布时间】:2020-12-29 03:11:54
【问题描述】:

我正在尝试设置一个 apache 反向代理来获得以下结果。

预期结果

访问https://service.example.com 时,apache 将提供来自http://localhost:8080 的内容,这是在本地主机上运行的另一个服务/网络服务器。

实际结果

访问https://service.example.com 时,apache 会返回来自https://example.com 的内容(并给出一些证书问题)。

当前配置

有一个 SSL apache 服务器在 https://example.com 运行,带有一个让我们加密通配符证书。

应该启用反向代理的虚拟主机文件如下所示

<VirtualHost *:80>
        ServerName service.example.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyRequests Off
        <Proxy *>
          Order deny,allow
          Allow from all
        </Proxy>

        ProxyPass / http://localhost:8080
        ProxyPassReverse / http://localhost:8080

        <Location />
          Order allow,deny
          Allow from all
        </Location>

   </VirtualHost>

该文件已使用 a2ensite service.conf 激活,并具有指向 /sites-enabled 的符号链接

如何解决这个问题?感谢所有帮助。

【问题讨论】:

    标签: apache ubuntu networking reverse-proxy


    【解决方案1】:

    如果问题仍然相关,您在域末尾缺少斜杠:

        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
    

    另外,不要忘记启用代理模块:a2enmod proxy_http

    【讨论】: