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>
ServerName www.example.com
ProxyPreserveHost Off
RewriteEngine On
RewriteRule ^(?:/app)?/assets/swf/(.*) http://app.example.com/assets/swf/$1 [P]
RedirectMatch /engine-name(.*) http://www.example.com/app$1
<Location /app>
ProxyPass http://app.example.com/engine-name
ProxyPassReverse http://app.example.com/engine-name
SetOutputFilter proxy-html
ProxyHTMLDocType "<!DOCTYPE html>"
ProxyHTMLURLMap ^/assets http://app.example.com/assets R
ProxyHTMLURLMap ^/system http://app.example.com/system R
ProxyHTMLURLMap /engine-name/ /app/
RequestHeader unset Accept-Encoding
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Details about the intentions behind all these directives can be found in a blog post.
Written by glaszig
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#