Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My team has written an internal BI server, which generates HTML reports at links such as /users/daily or /updates/questions.

The server is written in Grails, and it works perfectly with a classic Apache-Tomcat setting:

ProxyPass         /     http://localhost:8080/ nocanon
ProxyPassReverse  /     http://localhost:8080/

enter image description here


Is proxied internally to


And served from the Tomcat servlet.

The server is successful, and I would like to deploy it thrice, to 3 different systems, distinguished by a URL suffix (/dev, /stg, /prod):

enter image description here

Meaning that will be proxied from http://localhost:8080/users/daily, and will be served from http://localhost:8082/users/daily.

I have tried some Apache RewriteRules and ProxyPass rules, but could not find a working combination.

How can I do the suffix-based internal routing in Apache that with working internal links?

share|improve this question

1 Answer 1

You can do this with

<Location /dev>
  RewriteEngine on
  RewriteRule  ^/dev/(.*)  /$1
  ProxyPass         /  http://localhost:8080/ nocanon
  ProxyPassReverse  /  http://localhost:8080/

and so on. That will give you different proxies for the different URLs, and remove the leading /dev, /staging, or /prod from the URLs.

But there's a problem: links in the HTML coming back from Tomcat will have a URL base of /, not /dev etc. To add the prefix back into the HTML, you'll have to use mod_proxy_html or an equivalent to parse the HTML, modify it, and put it back together. That can work, but there's a performance cost; ill-formed HTML can get mangled; you'll have to rewrite URLs in CSS and Javascript too; and the Javascript may be impossible to get right.

Another option that may be easier: create new hostnames in DNS:,, and Then the URL rewriting would go away and you could do everything with virtual hosts, for example:

<VirtualHost *:443>
  ProxyPass         /  http://localhost:8080/ nocanon
  ProxyPassReverse  /  http://localhost:8080/

and so on.

share|improve this answer
Actually, I have implemented the subdomains solutions as a temporary workaround. I'll take a look at the mod_proxy_html docs. I think that this blog post might be helpful: – Adam Matan Aug 11 '14 at 14:00

Your Answer


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.