Ubuntu – Setup Apache as Front-end web server for Play 2.0 for multiple sites

Updated to add proxy permissions and single site config

Writing this as I ran into a couple of issues when setting up Apache as a front-end web server for a Amazon EC2 instance running two applications in Play, which I wanted to address from different domains with no port. The Play instructions are ok, but miss a couple of small things that tripped up a newb like me (not loading proxy http module or giving full path to modules).

1. Install apache – sudo apt-get install apache2

2. Enable http_proxy module – sudo a2enmod proxy_http

3. Update apache2.conf – sudo vim /etc/apache2/apache2.conf

with the following:

<VirtualHost *:80>
ProxyPreserveHost On
ServerName mydomainheadheader1.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy>
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>

<VirtualHost *:80>
ProxyPreserveHost On
ServerName 
mydomainheadheader2.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy>
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:81/
ProxyPassReverse / http://127.0.0.1:81/
</VirtualHost>

If you are only proxying for a single site you don’t need a VirtualHost, just (will forward all requests on port 80 to the proxy):

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>

ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/

4. Restart apache – sudo /etc/init.d/apache2 restart

The two sites hosted on your server should now be accessible from the domains.

If you muck up, errors should be logged in /var/log/apache2/error.log.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s