dina

dina

Need help with Nginx configuration, to serve phoenix app

Im trying to deploy the sample phoenix app on my Linode server but it doesn’t seem to work, I suspect the issue is in the Nginx config.

When I use port forwarding to forward all the traffic from port 80 to 4000
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=4000
the phoenix page is loaded so the parameters in the phoenix app must be configured properly.

I have a few sites hosted on the same server therefor I must use the Nginx.

The complete Nginx config located in /sites-available/phoenix is

server {
    listen 80;
    server_name www.mydomain.com;
    root /var/www/phoenix1/priv/static;
    access_log /var/log/nginx/phoenix.access.log;
    error_log /var/log/nginx/phoenix.error.log;
    client_max_body_size 12M;

    location / {
     index index.html
     try_files $uri @app;
    }

    location @app{
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_cache_bypass $http_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 Refrerer           $http_referer;
      proxy_set_header User-Agent         $http_user_agent;
      limit_req zone=phoenix burst=5 nodelay;
      proxy_pass "http://localhost:4000";
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
       allow all;
        log_not_found off;
        access_log off;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }
    location ~ /.well-known {
        allow all;
    }

    location ~ /\. {
        deny all;
    }
    location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        add_header Cache-Control public;
        access_log off; log_not_found off; expires 30d;
    }
    location ~* /(?:uploads|files)/.*\.*$ {
        deny all;
    }
}

the nginx.conf content is

worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
    use epoll;
    multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        limit_req_zone $binary_remote_addr zone=phoenix:10m rate=1r/s;
        limit_req_status 429;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        gzip on;
        gzip_disable "msie6";
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

Marked As Solved

ehayun

ehayun

This work fro me with no problem
proxy on 4000 to 80

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

# The Important Websocket Bits!
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";

		proxy_pass http://phoenix;
	}
}

Also Liked

dina

dina

great thanks for your help.
I set my nginx config as you suggested and removed all the other unnecessary staff, now it works

Last Post!

ehayun

ehayun

I am using https://letsencrypt.org/
It’s adding the necessary code for me on production
work fine

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement