Deploying Phoenix - Nginx

Deploying a Phoenix app is super simple. We are going to use an already existing application running the following:

1
2
Phoenix v1.1.4
Elixir 1.2.3

We will clone the application using git and our final setup will utilize nginx.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apt-get update
apt-get install nginx
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
apt-get update
apt-get install esl-erlang
apt-get install elixir
cd /srv/
ssh-keygen -t rsa -b 4096 -C "github@myemail.com"
cat ~/.ssh/id_rsa.pub
apt-get install git
git clone git@github.com:repo/myphoenixapp.git
cd myphoenixapp/
mix local.hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
apt-get install -y postgresql
apt-get install make gcc g++
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
apt-get install -y nodejs
npm install
npm install babel-preset-es2015
brunch build
mix ecto.create
mix ecto.migrate
mix phoenix.server

** A note that you may need to configure postgres to accept connections depending upon your setup.

Now we can go ahead and get nginx setup. Locate your nginx.conf. Likely it is located at /etc/nginx/nginx.conf and add the following

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
http {

  upstream phoenix_upstream {
    server 127.0.0.1:4000;
  }

  server {
    listen 80;
    server_name domainname.com;
    location / {
      proxy_redirect off;
      proxy_pass http://phoenix_upstream;
    }
  }

}

restart nginx with service nginx restart

and you should see your phoneix application on the domain provided.