vendredi 10 août 2018

Apache Server Reverse Proxy with ProxyPreserveHost On results in 404

I'm hoping someone here with experience with Apache can help me out. I have an internal server, that I'm fronting with Apache Reverse Proxy. i.e.

Apache Server: https://www.myexternalserver.com Internal Server: https://www.myinternalserver.com

Apache Settings

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

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

ProxyVia Off
ProxyRequests Off
ProxyPreserveHost On

SSLProxyEngine On
SSLProxyCheckPeerCN Off
SSLProxyCheckPeerExpire Off
SSLProxyCheckPeerName Off
SSLProxyVerify none

ProxyPass               /internal   https://www.myinternalserver.com
ProxyPassReverse        /internal https://www.myinternalserver.com

<Location />
        Allow from all
#       Require all granted
</Location>

The problem I'm having is such:

  • The internal application in code uses getRequest().getContextPath() to get the url. If I turn off ProxyPreserveHost and set it to Off, then the internal application ends up being the url that is returned. This is not what I want since this internal application url is not accessible to the public.
  • From what I've read, ProxyPreserveHost needs to be On so that the Apache Reverse Proxy can pass it's url to the underlying internal applications. When I do this however, I get a 404. I understand that what is probably happening is that the internal server is using the external domain to find its application and thus cannot find it. I'm not sure how to get around this. Btw, the internal application is hosted on PCF.

I would appreciate it if someone could help me out.

Thanks!

Aucun commentaire:

Enregistrer un commentaire