HTTPS 到 HTTP 的 Apache 反向代理

问题描述 投票:0回答:2

我正在尝试设置反向代理以将 https 请求重定向到 HTTP URL。我有一个 java 应用程序,它启动 tomcat 并在该 tomcat 实例上托管一些服务。

另一个应用程序将使用 https 调用这些服务,并且应该重定向 http url。以下是我所做的代理配置。

在 httpd.conf 中启用 mod_ssl.so、mod_proxy.so 和 mod_proxy_http.so 模块。并将以下 IFModule 添加到同一文件中。

<IfModule ssl_module>
        Listen 443
</IfModule>

以下是vhosts.conf文件的内容。

<VirtualHost *:443>
        ServerName domain.name.com
        ServerAdmin [email protected]
        DocumentRoot C:/Apache24/htdocs

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

        SSLEngine On
        SSLCertificateFile /certificate_path
        SSLCertificateKeyFile /privatekey_path
        SSLCertificateChainFile /chain_cert_path

        AllowEncodedSlashes NoDecode
        RequestHeader set X-Forwarded-Proto "https"
        RequestHeader set X-Forwarded-Port "443"

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

        RedirectMatch ^/metadata-agent$ /metadata-agent/
        ProxyPass /metadata-agent/ http://localhost:8084/ nocanon
        ProxyPassReverse /metadata-agent/ http://localhost:8084/

        RedirectMatch ^/tdv$ /tdv/
        ProxyPass /tdv/ http://localhost:9400/ nocanon
        ProxyPassReverse /tdv/ http://localhost:9400/

        ProxyErrorOverride Off
        ProxyPassReverseCookieDomain domain.name.com localhost
        ProxyPassReverseCookiePath / /
        ProxyPreserveHost on

        SSLProxyEngine On
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerExpire off

</VirtualHost>

我已经尝试了 SOF 中所有可能的答案。但没有任何作用。我收到以下 URL 的回复:

http://localhost:8084/tdv-soap/datasource/all

当我将其替换为 https://domain.name.com/tdv-soap/datasource/all 时,出现错误“无法访问服务器”。我还在主机文件中将 localhost 映射到域名。

非常感谢任何帮助。

apache reverse-proxy
2个回答
1
投票

问题出在代理通行证上。我已经做了下面提到的更正。

修正前:

RedirectMatch ^/metadata-agent$ /metadata-agent/
ProxyPass /metadata-agent/ http://localhost:8084/ nocanon
ProxyPassReverse /metadata-agent/ http://localhost:8084/

RedirectMatch ^/tdv$ /tdv/
ProxyPass /tdv/ http://localhost:9400/ nocanon
ProxyPassReverse /tdv/ http://localhost:9400/

修正后:

RedirectMatch ^/metadata-agent$ /metadata-agent/
ProxyPass / http://localhost:8084/ nocanon
ProxyPassReverse / http://localhost:8084/

RedirectMatch ^/tdv$ /tdv/
ProxyPass / http://localhost:9400/ nocanon
ProxyPassReverse / http://localhost:9400/

问题已解决。


0
投票

这在 apache httpd 2.4.6 (CentOS) 中对我有用,用于将到达端口 443 的 https 流量重定向到在 8080 上运行的 tomcat。我将其放入我的 VirtualHost 中:

<VirtualHost _default_:443>

    ...............

    ProxyPreserveHost On
# setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/
    #ProxyPassReverse / http://localhost:8080/
</VirtualHost>
© www.soinside.com 2019 - 2024. All rights reserved.