4

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

So

https://example.com/users/daily

Is proxied internally to

http://localhost:8080/users/daily

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 https://example.com/dev/users/daily will be proxied from http://localhost:8080/users/daily, and https://example.com/prod/users/daily 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?

Adam Matan
  • 12,504
  • 19
  • 54
  • 73

1 Answers1

6

You can do this with

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

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: dev.biserver.example.com, staging.biserver.example.com, and prod.biserver.example.com. Then the URL rewriting would go away and you could do everything with virtual hosts, for example:

<VirtualHost *:443>
  ServerName dev.biserver.example.com
  ProxyPass         /  http://localhost:8080/ nocanon
  ProxyPassReverse  /  http://localhost:8080/
</VirtualHost>

and so on.

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
  • 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: http://brian.olore.net/wp/tag/mod_proxy_html/ – Adam Matan Aug 11 '14 at 14:00