(1 of 4) Amazon ELB Multi-domain SSL forwarding to NGINX and Play Servers

Posted on Wednesday, April 10, 2013



(1 of 4  Install Scala and Play on Ubuntu 12.10)

This guide goes over setting up an ELB with a multi-domain SSL certificate.  The servers attached to the ELB will run multiple Play servers on different ports with an nginx server running in front of them to handle routing based on domain/subdomain names.

I know that is quite a mouthful but here is what I am trying to accomplish….

I want to run more than one Play Server on an ec2 instance.  Each Play Server will run on its own port.   I want to have a domain name to route to a specific Play server.  Ex.  www.example.com routes to the Play server running on port 9000 and  www2.example.com routes to the Play server running on port 8000.   In addition I want all the communication to be secure using ssl certificates.

For an individual server you could simply put a nginx server in front of the Play servers and have the nginx handle routing based on domain name.  But, in this case I want to add an AWS ELB (Elastic Load Balancer) in front of several EC2 machines.

Here is what I have found out thus far.   The ELB can handle the ssl certificate, but it can only have one certificate per ELB.  This forces you to use a multi-domain SSL certificate.   Also the ELB cannot port forward based on domain name so you still need an nginx server in front of the Play servers.




I want something like this.  The ELB handles the certificate and the nginx server handles the domain name routing.







Installing Scala Play on Ubuntu 12.10


I am going to install Scala play on an ubuntu 12.10 instance.

From the command line you could run the following


> sudo apt-get install scala


If you do this on Ubuntu 12.10 you get Scala 2.9.2 using OpenJDK




That is all well and good but I would rather use Java 1.7 from Sun and the latest scala build 2.10.0 so to do that install you need to first install java 1.7 to do that run the following commands


>  sudo apt-get purge openjdk*
>  sudo apt-get install python-software-properties
>  sudo add-apt-repository ppa:webupd8team/java
>  sudo apt-get update
>  sudo apt-get install oracle-java7-installer
>  java -version


.
 

Run the following command to download the .tgz file from scala and untar it


  > wget http://www.scala-lang.org/downloads/distrib/files/scala-2.10.0.tgz
  >  tar xf scala-2.10.0.tgz


Now place the scala program in /usr/bin/scala
And make a ln to it

    > sudo mkdir /usr/lib/scala
    > sudo mv scala-2.10.0 /usr/lib/scala/
    > sudo touch /usr/bin/scala
    > sudo ln -fs /usr/lib/scala/scala-2.10.0/bin/scala /usr/bin/scala
    >  sudo chmod a+x /usr/bin/scala



Testing Ubuntu

Open a new terminal and run scala


  > scala




Here you can see scala is using Java 1.7_0_17.




Install the Play Framework on Ubuntu


Download Scala Play and unzip it


> cd
> mkdir play
> cd play
> wget http://downloads.typesafe.com/play/2.1.0/play-2.1.0.zip
> unzip play-2.1.0.zip



Create a location to put the play software, put it in /usr/lib/play
And make a ln to it


    > sudo mkdir /usr/lib/play
    > sudo mv play-2.1.0 /usr/lib/play
    > sudo touch /usr/bin/play
    > sudo ln -fs /usr/lib/play/play-2.1.0/play /usr/bin/play
    >  sudo chmod a+x /usr/bin/play
   


Now a quick test.   Run this command


  > play




Play will attempt to start, but it has no project to run so it just quits.  It does display the version of Play, Java, and Scala you are using.

This is the bare bones set up. 




Create the 1st  scala program that will run on port 9000


Run the following command to create a Scala Play Application


> cd
> play new HelloWorld




Click enter then when presented with the option of scala or java use scala by entering 1


This creates a HelloWorld folder in the current directory.



Update the code


As a quick update go into the program and have it say

"Hello World this is the port 9000 Play server"



> cd
> vi HelloWorld/app/controllers/Application.scala






Update this portion of the code with the message and save it

Test It


Now that the web application has been created run it.



> cd HelloWorld
> play ~run



Open a web browser (assuming your server is running locally open it at this address)





Now this message appears in the header






Create the 2nd  scala program that will run on port 8000


Run the following command to create the second scala Play application


> cd
> play new HelloWorld2




Click enter then when presented with the option of scala or java use scala by entering 1


This creates a HelloWorld2 folder in the current directory.




Update the code


As a quick update go into the program and have it say

"Hello World this is the port 8000 Play server"



> cd
> vi HelloWorld2/app/controllers/Application.scala



Update this portion of the code with the message and save it



Test It

Now that the web application has been created run it on port 8000


> cd HelloWorld2
> play -Dhttp.port=8000  ~run


Open a web browser (assuming your server is running locally open it at this address)







Now this message appears in the header

No comments:

Post a Comment