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

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

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

1 Like

What about SSL?

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