user3565410
user3565410

Reputation: 31

how is reverse proxy done correctly with relative path

I have the following set up to mask/redirect a url with port to a proxy ex.

VirtualHost *:80>
ServerName psweb1.example.com
ServerAlias psweb1.example.com
ProxyPass /demo1 http://psweb1.example.com:8002/
ProxyPassReverse /demo1 http://psweb1.example:8002/
</VirtualHost>

The problem with this set up is that the redirection does not capture any of the relative paths.

For example psweb1.example.com:8002/main/login/login.jsp redirects to psweb1.example.com/demo1/main/login/login.jsp

Upon loggin in: The redirection does not follow the strucutre of psweb1.example.com/demo1/* Instead tries to go back to psweb1.example.com/*

How do I make sure of the proper mapping consistently stays with all the correct relative paths? such as:

psweb1.example.com:8002/main > psweb1.example.com/demo1/main
psweb1.example.com:8002/main/login > psweb1.example.com/demo1/main/login
psweb1.example.com:8002/side/* > psweb1.example.com/demo1/side/*

etc etc.

Upvotes: 3

Views: 6475

Answers (1)

larsks
larsks

Reputation: 312400

I think your problem here is actually absolute paths. I suspect that relative paths are working correctly. Consider:

Your browser fetches a page psweb.example.com/demo1/main/ which includes a link of the form <a href="login">...</a>. When you follow that link a browser, the browser will fetch /demo1/main/login, which is exactly what you want.

Now consider a link of the form <a href="/main/login">...</a>. This is an absolute link. In this case, your browser will fetch psweb.example.com/main/login.

You can't fix this with ProxyPass directives because it has nothing to do with the HTTP exchange between the browser and your server. This is an issue with the HTML content being generated by your web application. You typically have a few options:

  1. Correctly configure the web application. Many applications have a "base URL" setting of some sort designed exactly for this situation.

  2. Fix the web application. Edit the code to either (a) always generate relative links or (b) always prepend the correct base URL.

  3. Use an HTML filter, such as mod_proxy_html, which is available as part of recent versions (2.4 and later, I think) of Apache, and as a third-party module for earlier versions.

Upvotes: 1

Related Questions