Proxying Heroku App through Apache

Written by  on February 10, 2014 

I was trying to migrate a Heroku app to WordPress, but not all the pieces are complete. So we now have to proxy the Heroku app through Apache instances, and enable selective paths to be served natively while forwarding the rest of the request to Heroku with the same hostname. The stack is my usual Varnish/Apache/PHP at EC2. To accomplish this, I did the following:

  1. Heroku’s DNS is a RR-DNS, and can change at any notice. Do not use the IP address. Heroku’s proxy is proxy.heroku.com
  2. Varnish does not like RR-DNS for its backend directives (do not attempt to open a ticket… read this: https://www.varnish-cache.org/trac/ticket/1334)
  3. Configured Apache’s ProxyPass with the following:
    ProxyPass /wordpressapp !
    ProxyPass / http://proxy.heroku.com/
    ProxyPassReverse / http://proxy.heroku.com/
    ProxyPreserveHost On

    The first options define the paths that should not be proxied. The last directive (http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost) forwards the hostname to the proxy, so Heroku can serve up the right app.

Simple, elegant, and not so obvious. Note that you cannot alter the HTTP hostname, so if you need to do something more crazy, you can chain a mod_rewrite rule to another internal VirtualHost that has a fake hostname, and then do the ProxyPass.

Category : apacheherokuvarnish

Leave a Reply

Your email address will not be published. Required fields are marked *