Deploying phoenix with Nginx

Hello,
I am on my way deploying a phoenix app in a remote droplet by DO. Using a nginx server. So, I have created my server, all working, but on port :4000 (obviously). I am trying to forwards this port to my domain example.com, but something isnt right for sure. Viewed this post Need help with Nginx configuration, to serve phoenix app, but frankly idk what more to do.

My /etc/nginx/sites-available/example.com

upstream phoenix {
  server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
}
server {
        server_name  iex.venus.home;
        listen 80;
        client_max_body_size 30M;
        location / {
                allow all;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-Cluster-Client-Ip $remote_addr;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_pass http://phoenix;
        }
}

And my phoenix app is located (if necessary) → /var/www/example.com/phoenix.

The way is that my application is visible on IP:4000, but I want it forwarded to example.com. Hope everything is clear.

Best Regards,
ykostov

1 Like

Does your server config have a symbolic link to nginx/sites-enabled?

1 Like

check this video video if it helps

I don’t know how to help you with your Nginx configuration but I can suggest you a more easy and automated setup, that I use for my Video Notes web app running on DO with Traefik and Docker.

I have automated the creation of the server with Traefik, Docker and LetsEncrypt via a cloud-init file that you upload when creating the dropplet:

The cloud-init file will also do a lot of security hardening during the creation of the server.

1 Like

You need to tell us what is the symptom, or it is very hard to help you. The relevant part of my config file is:

        location / {
                 proxy_set_header Host $host;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 proxy_set_header X-Forwarded-Proto  $scheme;
                 proxy_set_header X-Forwarded-Host  $host;
                 proxy_set_header X-Forwarded-Port  $server_port;
                 proxy_pass http://localhost:4001/;
                 proxy_redirect off;
        }
        # required for websocket
        location /live {
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection "upgrade";
                 proxy_set_header Host $host;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 proxy_set_header X-Forwarded-Proto  $scheme;
                 proxy_set_header X-Forwarded-Host  $host;
                 proxy_set_header X-Forwarded-Port  $server_port;
                 proxy_pass http://localhost:4001/live;
                 # raise the proxy timeout for the websocket
                 proxy_read_timeout 6000s;
        }
1 Like

@ykostov please check this. Also you can run sudo nginx -t to check if your configuration is valid.
You can create the symbolic link with below command after moving to /nginx/sites-enabled directory
sudo ln -s ../sites-available/xyz.conf xyz.conf.
And check if the nginx service itself is running.

1 Like