Last Updated: February 25, 2016
· glaszig

Reverse Proxy a mountable Rails Engine with Apache

Last week I had to figure out how to proxy a mounted Rails engine with Apache.

To do this you'll have to properly wire up mod_proxy and mod_proxy_html:

<VirtualHost *:80>

  ProxyPreserveHost Off

  RewriteEngine On
  RewriteRule   ^(?:/app)?/assets/swf/(.*)$1 [P]

  RedirectMatch /engine-name(.*)$1

  <Location /app>
    SetOutputFilter  proxy-html
    ProxyHTMLDocType "<!DOCTYPE html>"
    ProxyHTMLURLMap  ^/assets R
    ProxyHTMLURLMap  ^/system R
    ProxyHTMLURLMap  /engine-name/ /app/
    RequestHeader    unset Accept-Encoding
    Order            allow,deny
    Allow            from all

Details about the intentions behind all these directives can be found in a blog post.