0

I have configured a reverse proxy in Apache2. It gets requests by HTTPS - unwraps the HTTPS and then forwards to local HTTP-processes for /web and /rest.

<VirtualHost *:4443>
    ProxyPass /web http://127.0.0.1:8080/web
    ProxyPassReverse /web http://127.0.0.1:8080/web

    ProxyPass /rest http://127.0.0.1:8181
    ProxyPassReverse /rest http://127.0.0.1:8181

    ServerName myserver123.abc.xyz.org
    ProxyPreserveHost On

    SSLEngine On
    SSLProxyEngine On
    SSLCertificateFile /etc/apache2/certs/server.cer
    SSLCertificateKeyFile /etc/apache2/certs/server.key

This is working fine. Every request to / is forbidden.

But now I try to forward every request to / to /web instead of the 403-forbidden response.

I inserted this before the ServerName line.

    ProxyPass / http://127.0.0.1:8080/web
    ProxyPassReverse / http://127.0.0.1:8080/web

But does not work.

All I get in the browser is

Bad Request Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.

How can I get me forward from / to /web?

2 Answers 2

1

ProxyPass is the wrong option to create a redirect. You do not want to proxy someone who visits / to the backend, but you want to redirect them to another path on the proxy.

For that, you could use a RedirectMatch.

RedirectMatch ^/$ /web

For more examples, see the official docs.

0

RewriteRule is very powerful when combined with the [P] flag to provide various rules and redirects. You can do an exact match and have different capture groups. You can also use the Last flag so that it doesn't continue to later rules.

RewriteRule '^/rest(/.*)?' http://127.0.0.1:8181$1     [NC,P,L]
RewriteRule '^(/.*)?'      http://127.0.0.1:8180/web$1 [NC,P,L]

ProxyPassReverse /rest     http://127.0.0.1:8181
ProxyPassReverse /         http://127.0.0.1:8080/web

Your error also implies that you should be connecting as https:// instead of http://.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .