Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a web application running on port 8080 on my server: myip:8080/app

I have the following config in my httpd.conf

<VirtualHost *:80>
 ServerName subdomain.mydomain.com
 ServerAlias mydomain.com
 ProxyPass /app http://localhost:8080/app/
 ProxyPassReverse /app http://localhost:8080/app/
</VirtualHost>

This works fine and makes the app available at subdomain.mydomain.com/app

Now I'm struggling to make it available at subdomain.mydomain.com (without the /app). I first tried

<VirtualHost *:80>
 ServerName subdomain.mydomain.com
 ServerAlias mydomain.com
 ProxyPass / http://localhost:8080/app/
 ProxyPassReverse / http://localhost:8080/app/
</VirtualHost>

and also added

ProxyHTMLURLMap /app/ /

but both don't seem to work. The main page loads, but all javascript and CSS links still point to /app/... which returns the main html page instead of the asset.

What am I missing? Am I on the right track or is there a completely different (better) way to achieve this?

The application is a Tapestry web application in Tomcat 7 on Ubuntu 12.04.

Any insights on performance would be interesting too.

share|improve this question
add comment

3 Answers

ProxyPassReverse works only on HTTP headers (e.g.: 301 redirects).

To enable HTML rewrite, you need to enable it via:

ProxyHTMLEnable On
ProxyHTMLURLMap /app/ /

However, modern web applications can easily understand what is going on from the HTTP request made by reverse proxies, and no additional tuning at the proxy level is usually necessary in this case.

Keep in mind thatmod_proxy_html add some overhead in processing those requests.

share|improve this answer
1  
Can you please clarify what you mean by "understand what is going on"? Are they emitting only relative links, or rebasing the links to / instead of /app based on some information that's sent in the proxy request? Whether a web app will do that is going to be highly dependent on how it's built. –  Andrew Schulman Jan 4 at 11:57
    
Both approaches are better than nothing, but the second one is more robust than simply outputting relative links. I understand that such behaviour is unreachable without using specific technologies (e.g.: MVC architecture with a single application entrypoint for every request), but hey, we are in 2014. –  Giovanni Toraldo Jan 4 at 12:01
add comment

Your web application at myip:8080/app probably has a lot of absolute paths in HTML and JS beginning with /app/... which cannot all be caught and rewritten by mod_proxy_html.

I would suggest to first try to get your app running at different local URLs like myip:8080/blah. Fire up the developer toolbar of your browser and check the network tab for files that are still getting requested at /app/... and fix them until they work at both URLs (/blah and /app).

The goal should be that all your links in your app are relative, i.e. specified as

<script type="text/javascript" src="file.js"></script>

instead of something like this

<script type="text/javascript" src="/app/file.js"></script>

Also check out the <base> tag for a way to override the default base URL.

share|improve this answer
add comment

Giovanni's answer brought me on the right track. I needed to add

ProxyHTMLEnable On

or more precisely (for my version of mod_proxy_html) the equivalent

SetOutputFilter INFLATE;proxy-html;DEFLATE

However I decided to use it in combination with a rewrite (since I couldn't get the Tapestry event links to work any other way):

<VirtualHost *:80>
 ServerName subdomain.mydomain.com
 ServerAlias mydomain.com
 ProxyRequests Off
 ProxyPreserveHost On
 SetOutputFilter INFLATE;proxy-html;DEFLATE     
 ProxyPass / http://localhost:8080/app/
 ProxyPassReverse / http://localhost:8080/app/
 ProxyHTMLURLMap /app/ /     
 ProxyPassReverseCookiePath /app /
 RewriteEngine on
 RewriteRule ^/app/(.+) /$1 [R,L]
</VirtualHost>

I also needed to adapt the cookie path (ProxyPassReverseCookiePath /app /) for my Tomcat session cookie to work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.