Play Framework App behind Apache (co-deploying play application with other sites)

Manytimes we need to host multiple websites/applications on a single host - e.g., say a wordpress (php) blog with a play app or 2 play apps on a single host. One of the simplest way to achieve this is to use apache as a frontend proxy routing traffic back to the right application based on domain name.

(Ideally you may want to use lighter web servers like nginx instead of apache, but many times one may be already using apache for other sites)

Apache supports mod_proxy to configure such a routing (the standard name for this configuration is reverse proxy).

Say you are running your play app on port 9000 and want to use apache (running on port 80/443) to redirect traffic for to this play app. Here is the sample apache2 virtualhost configuration:

<VirtualHost *:80>
  ServerAdmin <email>

  ProxyPreserveHost On
  ProxyPass  /excluded !
  ProxyPass /
  ProxyPassReverse /


Do make sure to enable mod_proxy to make it work though. On ubuntu/debian this can be achieved using a2enmod proxy followed by apache reload.

A typical error seen during such configuration is following:

AH01144: No protocol handler was valid for the URL /home. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

If you see this error, you can fix this by adding following lines to your apache site configuration file (outside <VirtualHost> declaration)

LoadModule proxy_module modules/
LoadModule proxy_http_module modules/
Category: play-framework