ykostov

ykostov

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

Most Liked

crova

crova

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

Exadra37

Exadra37

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.

derek-zhou

derek-zhou

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;
        }

Last Post!

akashv

akashv

@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.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement