Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use "Redirect" and "ProxyPass"

I would like to force my users to use https to log in. Unfortunately the "redirect" directive does not seem to work in cunjunction with "ProxyPass"

<VirtualHost *:80>
  ServerName www.domain.com
  # This does not work
  Redirect permanent /app/login.jsp https://www.domain.com/app/login.jsp
  ProxyPass         /app    http://localhost:8080/app
  ProxyPassReverse  /app    http://localhost:8080/app
</VirtualHost>

Any idea ? Thanks.

like image 980
Yann Avatar asked Oct 27 '14 19:10

Yann


People also ask

What is the use of ProxyPass?

ProxyPass is the main proxy configuration directive. In this case, it specifies that everything under the root URL ( / ) should be mapped to the backend server at the given address.

What is ProxyPass and ProxyPassReverse in httpd conf?

ProxyPassReverse will intercept those headers, and rewrite them to match the Apache proxy server. ProxyPass will create a reverse proxy. A reverse proxy (or gateway), appears to the client just like an ordinary web server. The client makes ordinary requests for content in the namespace of the reverse proxy.

What does ProxyPassReverse mean?

ProxyPassReverse. The directive ProxyPassReverse lets Apache adjust the URL in the Location header on HTTP redirect responses. For instance this is essential when Apache is used as a reverse proxy to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.


2 Answers

Found an answer to this question here:

https://serverfault.com/questions/605931/can-you-use-redirect-and-proxypass-at-the-same-time

The following needs to be added before the other proxypass directives:

ProxyPass /app/login.jsp !

like image 65
Rune Stilling Avatar answered Oct 18 '22 10:10

Rune Stilling


I had a more complicated use case and it required the use of ProxyPassMatch. It went a little something like this:

ProxyPassMatch ^/app(/(index.html)?)?$ !
RedirectMatch ^/app(/(index.html)?)?$ /path/to/login/page.html

ProxyPass /app/* http://remote-server/app
ProxyPassReverse /app/* http://remote-server/app

I had to use ProxyPassMatch because ProxyPass otherwise performs prefix-matching. You need to match on the end-of-string, so ProxyPassMatch with a $ regular expression metacharacter is critical.

Here, RedirectMatch is used in the same way, because Redirect also performs prefix-matching as well. The two directives also have a nice symmetry, too.

like image 40
Christopher Schultz Avatar answered Oct 18 '22 11:10

Christopher Schultz