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

Amazon EC2 – Mongo Play Scala Instance setup guide

EDIT: These instructions are now out of date as the SBT and Play dependences now need to be installed via the Typesafe Activator, see the Play Framework documentation for details.

This is a quick guide on how to create an EC2 instance with Mongo DB and Play/Scala, allowing you to quickly spin up a server and put your application online in half an hour or less. You can do all this with the AWS Free usage tier, so it costs nothing.

Chosen Play/Scala cause it’s what I’m working with now, but the same advantages apply to any other open source frameworks and dbs. Play/Scala is insanely easy and quick to use, see James Hughes great starter guide for info. All the info below was available online but not in one place or covering some of the tricks that held me up as a newbie.

1. Log into AWS EC2 and create Instance

– Ubuntu Server Instance (12.04 used for this example)

– Security group open SSH – 22, HTTP –  HTTPS – 443, TCP – 80 (add more if necessary), TCP – 28017 (mongo)

2. SSH into server (see AWS Management Console -> My Instances -> Instance Actions -> Connect, replace “root” user with “ubuntu” in connection string)

3. Install Mongo

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian-or-ubuntu-l…

http://amath.colorado.edu/computing/unix/vi/ – using vi to edit the list file

4. Install OpenJDK for Play/Scala (Play 2.0 requires JDK 6+)

http://www.wikihow.com/Install-Java-on-Linux – see “Ubuntu method using a Console”

5. Install SBT

– https://github.com/harrah/xsbt/wiki/Getting-Started-Setup (your play app will require sbt-launch.jar and an sbt script)

6. Install GIT (optional, but makes life much easier when retrieving/updating your app)

– sudo apt-get install git-core

– git clone https://USERNAME@github.com/USER/PROJECT.git (clone repo from git repo, will prompt for password)

– git pull (use later to get latest version)

7. Run SBT to download required libs and compile

– ./sbt (in project directory, it will download all scala/play libraries required, may take a while)

– start 80 (need to run as root to use port 80 or whatever port you want)

– Browse to ec2-999-999-999-999.compute-9.amazonaws.com:PORT to view your application (get AWS public dns from AWS EC2 console)


That’s it. At any point in the process you can create a snapshot of your image which you can use to generate a template image for future instances, so you don’t have to do the steps again.
You can also use the AWS command line tools to do all of the above by script, allowing you to spin up templated images, deploy latest code and start up applications, all completely automated. You can use this to build a full Dev/CI environment all with zero on site infrastructure.
Extra Links: