Deploying Simple NON Phoenix apps on VPS ( linode / Digital ocean) with Git
#-- Follow this great writeup for prerequisites- having erlang/elixir/gitinstalled. | |
#-- Setting up repos on the vps etc. | |
#-- http://gabrieljaldon.com/articles/deploying-phoenix-with-git.html | |
# In my case - I'M NOT USING PHOENIX I had to modified the post-receive hook in the repo | |
#-------- post-receive hook | |
#!/bin/bash | |
git --work-tree=/<your>/<path>/<toyour.app> --git-dir=/<your>/<path>/<toyour.REPO> checkout -f; | |
cd /<your>/<path>/<toyour.app> | |
function restart { | |
PORT=8888 mix do deps.get, deps.compile && MIX_ENV=prod PORT=$1 elixir --detached -S mix run --no-halt | |
} | |
# Find previous running process | |
previous_port=$(lsof -t -i:4090) | |
if [ -n $previous_port ]; then | |
kill $previous_port; | |
restart 4090 | |
else | |
restart 4090 | |
fi | |
sleep 2 # not sure if needed | |
previous_port=$(lsof -t -i:4092) | |
if [ -n $previous_port ]; then | |
kill $previous_port; | |
restart 4092 | |
else | |
restart 4092 | |
fi | |
#---- END post-receive hook | |
#---- MY NGINX CONFIG. NGINX >= 1.4 | |
upstream YOURNAME { | |
server 127.0.0.1:4090; | |
server 127.0.0.1:4092; | |
} | |
server { | |
listen 80; | |
root /<your>/<path>/<toyour.app>; | |
server_name example.com www.example.com; | |
try_files $uri/index.html $uri @YOURNAME; | |
location / { | |
proxy_pass http://YOURNAME; | |
proxy_set_header Host $host; | |
# WebSocket support (nginx 1.4) | |
proxy_http_version 1.1; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
error_page 500 502 503 504 /500.html; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment