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

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement