Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am attempting to properly set up Play Framework with Nginx as the front-end HTTP server on Amazon AMI.

I am a bit confused by the official documentation set out by Play. Are they suggesting that you run

start -Dhttp.port=9000

and then configure Nginx to reroute to port 9000 in order to properly serve up my app? I feel like having a dedicated user just to run the start command is a waste, isn't there a better way to do this?

I would really appreciate some basic strategies for best practices for a production Play Framework web app.

share|improve this question

1 Answer 1

The reason I use a dedicated user for this is so that I can put a number of different environments on a single machine, they are all kept from treading on each other by the separate user id. For example we have an app called "d1" which we have to put into several environments so we have a user for each environment:

d1test d1development d1nightly

For the nightly build the nginx.conf looks like:

upstream d1nightly {
  ip_hash;
  server 127.0.0.1:20101;
  server 127.0.0.1:20102;
 }

 server {
  listen 443 ssl;
  server_name nightly.d1.org;
  ssl_certificate      /etc/ssl/certs/cert.pem;
  ssl_certificate_key    /etc/ssl/private/key.pem;
  ssl_session_timeout 5m;
  ssl_protocols SSLv3 TLSv1;
  ssl_ciphers HIGH:!ADH:!MD5;
  ssl_prefer_server_ciphers on;
  location /500x.html {
    alias /usr/share/nginx/html/500x.html;
  }


  location / {
   proxy_set_header Host $http_host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-Proto https;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_redirect http:// https://;
   add_header Pragma "no-cache";
   proxy_pass http://d1nightly;
   error_page 500 502 503 504 /500x.html;
  }
 }

Now when we go to nightly.d1.org we get the nightly release.

We pay a fixed rate per VM per hour rather than for CPU time so it we get more value for money with this combination by packing 3 or 4 environments onto a single machine during our testing.

For starting the play applications, I've got a really basic shell script function:

function startPlayAppd1 {
        #start a d1 play app with appropriate system properties
        nohup ${base_directory}/${app}-latest-${jvm}/${snapshot_name}/start \
                       -Dhttp.port=${listen_port}                                             \
                       -Denv.name=${env_name}                                                 \
                       -Dlogger.file=${logger_file}                                           \
                       -Dsession.secure=${session_secure}                                     \
                       -Dga.domain=${ga_domain}                                               \
                       -Djava.net.preferIPv4Stack=${preferIPv4Stack}                          \
                       -Dcom.sun.management.jmxremote                                         \
                       -Dcom.sun.management.jmxremote.port=${jmx_port}                        \
                       -Dcom.sun.management.jmxremote.authenticate=${jmx_remote_authenticate} \
                       -Dcom.sun.management.jmxremote.password.file=jmxremote.password        \
                       -Dcom.sun.management.jmxremote.access.file=jmxremote.access            \
                       -Dcom.sun.management.jmxremote.ssl=false                               \
                       -Djavax.net.debug=${javaxDebugLevel}                                   \
                > ${listen_port}.nohup 2>&1 &
        sleep 5
}

The other advantage of an environment per user is the flexibility it creates.

As you can see various system properties have been added, for example to enable JMX so our monitoring tools can observe the play applications.

This is one solution which has worked well for our use cases.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.