Skip to content

Instantly share code, notes, and snippets.

@michalvalasek
Created February 9, 2016 19:44
Show Gist options
  • Save michalvalasek/be8eaff327e4dee6f96f to your computer and use it in GitHub Desktop.
Save michalvalasek/be8eaff327e4dee6f96f to your computer and use it in GitHub Desktop.
Phoenix app upstart & nginx conf
# nginx config in /etc/nginx/sites-available/appname
upstream appname {
server 127.0.0.1:8888;
}
# The following map statement is required
# if you plan to support channels. See https://www.nginx.com/blog/websocket-nginx/
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server{
listen 80;
server_name .hostname.com;
location / {
try_files $uri @proxy;
}
location @proxy {
include proxy_params;
proxy_redirect off;
proxy_pass http://appname;
# The following two headers need to be set in order
# to keep the websocket connection open. Otherwise you'll see
# HTTP 400's being returned from websocket connections.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
description "appname"
## Uncomment the following two lines to run the
## application as www-data:www-data
#setuid www-data
#setgid www-data
start on runlevel [2345]
stop on runlevel [016]
expect stop
respawn
env MIX_ENV=prod
export MIX_ENV
## Uncomment the following two lines if we configured
## our port with an environment variable.
env PORT=8888
export PORT
## Add app HOME directory.
env HOME=/app
export HOME
pre-start exec /bin/sh /app/bin/appname start
post-stop exec /bin/sh /app/bin/appname stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment