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
  2. Varnish does not like RR-DNS for its backend directives (do not attempt to open a ticket… read this:
  3. Configured Apache’s ProxyPass with the following:
    ProxyPass /wordpressapp !
    ProxyPass /
    ProxyPassReverse /
    ProxyPreserveHost On

    The first options define the paths that should not be proxied. The last directive ( 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 *