Skip to content

Instantly share code, notes, and snippets.

@leon
Created February 22, 2013 08:23
Show Gist options
  • Save leon/5011724 to your computer and use it in GitHub Desktop.
Save leon/5011724 to your computer and use it in GitHub Desktop.
Ubuntu play nginx configuration
# Upstart file to make play app start when server starts
description "PlayFramework 2"
author "Leon Radley <[email protected]>"
version "1.0"
env USER=myuser
env GROUP=mygroup
env HOME=/home/myuser/app
env PORT=9000
env ADDRESS=127.0.0.1
env CONFIG=production.conf
env SBTMEM=256
env EXTRA="-Xms512M -Xmx1024m -server"
env RUNEVOLUTIONS=true
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
expect daemon
# If you want the upstart script to build play with sbt you can uncomment this
# Though you will need sbt on the server and it takes alot of memory
#pre-start script
# chdir $HOME
# sbt clean compile stage -mem $SBTMEM
#end script
pre-start script
#mkdir -p ${LOGDIR}
rm -f ${HOME}/RUNNING_PID
end script
# use --no-close when ubuntu 12.10 is available
exec start-stop-daemon --pidfile ${HOME}/RUNNING_PID --chuid $USER:$GROUP --exec ${HOME}/start --background --start -- "$EXTRA -Dconfig.resource=$CONFIG -Dhttp.port=$PORT -Dhttp.address=$ADDRESS -DapplyEvolutions.default=$RUNEVOLUTIONS -DapplyDownEvolutions.default=$RUNEVOLUTIONS"
server {
listen 80;
server_name www.myapp.com;
root /home/myuser/app;
include /etc/nginx/proxy_params;
location / {
proxy_pass http://127.0.0.1:9000;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
}
@leon
Copy link
Author

leon commented Feb 22, 2013

to run play without nginx iptables can be usedto port forward port 9000 to 80

/sbin/iptables -t nat -F 
/sbin/iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80 -j REDIRECT --to-ports 9000 
/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 9000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment