Trying to deploy phoenix project on AWS server

I am new with web development. I am trying to deploy the phoenix project on the AWS server, I installed ubuntu with Nginx. I am able to see the Nginx page when checking with my IP address. Then I configured Nginx file as shown below:

####
http {
  upstream phoenix_upstream {
    server 15.134.23.13:4001;
  }
 
  server {
    listen 80;
    location / {
      proxy_redirect off;
      proxy_pass http://phoenix_upstream;
    }
  }
}
####

My mix phx.server command runs without error and I am able to see the following output:

18:00:03.901 [info] Running TestingWeb.Endpoint with cowboy 2.8.0 at :::4001 (HTTP)

18:00:03.910 [info] Access TestingWeb.Endpoint at http://15.134.23.13:4001

But still, I am getting the Nginx default page only. No phoenix page.

Hello and welcome…

I think your nginx configuration is incomplete… see this post

Now my file is :

upstream calabrese_4000 {
	server 15.134.23.13:4001 max_fails=5 fail_timeout=60s;
}
server {
	listen 80;
	listen [::]:80;
	index index.html index.htm index.nginx-debian.html;
	server_name 15.134.23.13;
	location / {
		# Proxy
		proxy_pass http://calabrese_4000;
		proxy_pass_header Server;
		proxy_set_header Host $http_host;
		proxy_redirect off;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Scheme $scheme;

		# WebSocket support
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
	}
}

Using this I am getting 504 gateway timeout error.
When I changed

server_name 15.134.23.13;

to

server_name HTTP://15.134.23.13/;

I am getting same Nginx page.

Hi,

Thanks for your prompt reply.
There is some progress, now I am getting 504 gateway timeout error.

If you want to start minimalist you can also get nginx out of the way for now and just use elixir to serve port 80:

1. Allow elixir to bind to port 80 without beeing root:

> sudo setcap CAP_NET_BIND_SERVICE=+eip `elixir -e ":os.cmd('readlink /proc/#{:os.getpid()}/exe') |> :string.trim |> IO.puts"`

(This line is long but it needs to find the real executable beam.smp and give it the network capability to bind any port)

2. Stop nginx (if it’s running)

sudo systemctl stop nginx

3. Update your app to run on port 80

nano config/dev.exs

Replace [port: 4000] there with [port: 80]

4. Start your app again

mix phx.server

done!

1 Like

Yes, it’s working fine with these setting. So there is definitely an issue of Nginx config settings.

P.S: one typo error after “string.trim”

1 Like

Please tell me how to reset the STEP one. If I want to do an experiment with Nginx config settings, do I need to reset those settings of PORT?