Ramu Chowdam
Ramu Chowdam

Reputation: 33

Apache reverse proxy for HTTPS to HTTP

I'm trying to set up a reverse proxy to redirect https request to HTTP URL. I've a java application which brings up tomcat and hosts some services on that tomcat instance.

Another application will be invoking these services using https and this should be redirected http url. Below is the proxy config that I did.

Enabled mod_ssl.so,mod_proxy.so and mod_proxy_http.so modules in httpd.conf. And also added below IFModule to same file.

<IfModule ssl_module>
        Listen 443
</IfModule>

Below is the content of vhosts.conf file.

<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>

I've tried all the possible answers available in SOF. But nothing is working. I'm getting a response with the below URL:

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

when I'm replacing it with https://domain.name.com/tdv-soap/datasource/all, getting the error "server can't be reached". I've also mapped localhost to domain name in hosts file.

Any help is highly appreciated.

Upvotes: 0

Views: 5072

Answers (2)

Don Smith
Don Smith

Reputation: 563

This worked for me in apache httpd 2.4.6 (CentOS) for redirecting https traffic arriving on port 443 to my tomcat running on 8080. I put this inside my 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>

Upvotes: 0

Ramu Chowdam
Ramu Chowdam

Reputation: 33

The issue was with the proxy pass. I've made the Corrections mentioned below.

Before Correction:

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/

After Correction:

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/

This has resolved the issue.

Upvotes: 1

Related Questions