peterweyand

peterweyand

I’m attempting to deploy a Phoenix/Elixir application over docker-compose and nginx and it’s not working. I’m stuck on how to debug. Here’s how I’ve set up the application so far -

This is my docker-compose file

version: "3.9"

networks: 
  main_network:

volumes:
  volume1:
  varwwwcertbot:
  certbotconf:
  data_volume:

services:
  phx: 
    build:
      context: ./phx
    restart: always
    volumes:
      - ./phx:/phx
    ports: 
      - "4000:4000"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - main_network
  db:
    image: postgres
    restart: always
    volumes:
      - ./docker-entrypoint-initdb.d/init.sql:/docker-entrypoint-initdb.d/init.sql
      - data_volume:/var/lib/postgresql/data
    environment:
      - POSTGRES_NAME=dev-postgres
      - POSTGRES_USER=pixel
      - POSTGRES_DATABASE=lightchan
      - POSTGRES_PASSWORD=exploration 
    ports: 
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U pixel"]
      interval: 5s
      timeout: 5s
      retries: 20
    networks:
      - main_network
  frontend:
    build: 
      context: ./frontend
    restart: always
    volumes:
      - './frontend:/app'
      - '/app/node_modules'
    ports: 
      - "3000:3000"
    networks:
      - main_network
    depends_on:
      - "phx"
  nginx:
    build:
      context: ./nginx
    restart: always
    ports:
      - "80:80"
      - "443:443" 
    volumes:
      - volume1:/usr/share/nginx/html
      - varwwwcertbot:/var/www/certbot
      - certbotconf:/etc/letsencrypt 
    networks:
      - main_network
  certbot:
    image: certbot/certbot:latest
    volumes: 
      - varwwwcertbot:/var/www/certbot
      - certbotconf:/etc/letsencrypt
    networks:
      - main_network

Here’s my Dockerfile for phoenix -

#FROM ubuntu:latest

FROM alpine:latest

COPY . .

#WORKDIR ./phx

#RUN apt-get update -y

#RUN apt-get install wget -y

#RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && dpkg -i erlang-solutions_2.0_all.deb

#RUN sudo apt-get update

#RUN sudo apt-get install esl-erlang

#RUN sudo apt-get install elixi

RUN apk add inotify-tools

RUN apk add elixir

#RUN echo "mix deps.get"

#RUN mix deps.get

RUN echo "mix local.hex --force"

RUN mix local.hex --force

RUN echo "mix deps.get"

RUN mix deps.get

RUN echo "mix local.rebar --force"

RUN mix local.rebar --force

RUN echo "mix phx.server"

EXPOSE 4000

ENTRYPOINT ["sh", "./entrypoint.sh"]

and here’s my entrypoint.sh

#!/bin/bash

#echo "mix deps.get"

#mix deps.get

#echo "mix local.hex --force"

#mix local.hex --force

#echo "mix local.rebar --force"

#mix local.rebar --force

#echo "mix phx.server"

mix phx.server

and my NGINX

events{

}

http{

     map $http_upgrade $connection_upgrade {
         default Upgrade;
         ''      close;
     }

     upstream websocket {
         server 164.92.157.124:4000;
     }

     server {
         listen 80;
         server_name localhost lightchan.org www.lightchan.org;
         root /usr/share/nginx/html;
	
 	 location /.well-known/acme-challenge/ {
            root /var/www/certbot;
         }
     	
         if ($scheme = http) {
   	   return 301 https://lightchan.org$request_uri;
 	 }
     }

    server {
         listen 443 default_server ssl http2;
         listen [::]:443 ssl http2;
         server_name localhost lightchan.org www.lightchan.org;
         ssl_certificate /etc/letsencrypt/live/lightchan.org/fullchain.pem;
         ssl_certificate_key /etc/letsencrypt/live/lightchan.org/privkey.pem;

            location /media/pics/ {
                 autoindex on;
            }
            location / {
     	         proxy_pass http://frontend:3000;
                 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        Host $http_host;
                 proxy_intercept_errors  on;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection "upgrade";
            }
            location ^~ /socket/ {
                 proxy_pass http://websocket;
                 add_header X-uri "$uri";
                 proxy_http_version 1.1;
                 proxy_set_header        X-Forwarded-Proto $scheme;
                 proxy_set_header        Host $host;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection $connection_upgrade;
                # proxy_set_header Upgrade $http_upgrade;
                # proxy_set_header Connection "upgrade";
            }
            location ^~ /api/ {
                 proxy_pass http://phx:4000;
                 add_header X-uri "$uri";
                 proxy_http_version 1.1;
                 proxy_set_header        X-Forwarded-Proto $scheme;
                 proxy_set_header        Host $host;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection $connection_upgrade;
                # proxy_set_header Upgrade $http_upgrade;
                # proxy_set_header Connection "upgrade";
            }
    }
}
phx_1       | [info] Running MyAppWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http)
phx_1       | [info] Access MyAppWeb.Endpoint at http://<IPADDRESS>:4000
phx_1       | [watch] build finished, watching for changes...

Currently the application will not navigate to www.lightchan.org/api or www.lightchan.org/socket - but returns a 502 gateway error, which tells me that NGINX is seeing the route, but the application isn’t responding. My docker-compose logs show that the application is up but not receiving incoming data - there’s no logs after navigating to that address.

I’ve changed config/config.exs in the phoenix application to take localhost, 127.0.0.1, and <IPADDRESS>, with the port number of 4000 and then attempted to run mix phx.server by itself without docker and nginx in order to see if I could reach the / splash page. This works on my local machine on localhost, but not at all on the server for either of the three options.

Connection upgrade to handle websockets is configured correctly, and SSL works with the front page application which tells me that docker name spaces with the networking option are up. I have this error in the web console (socket.js:216 WebSocket connection to ‘wss://www.lightchan.org/socket/websocket?userToken=1647970833615&vsn=2.0.0’ failed: ) when connecting to the frontend and attempting to open a socket because the server can’t be reached.

At this point I’m out of ideas. I’ve asked on a number of forums and on stack overflow but I can’t seem to make this work. Does anyone have any ideas?

Showing Posts 1 to 4

peterweyand

peterweyand OP

Never mind if anyone cared. Someone told me the answer.

Exadra37

Exadra37

That is not a correct attitude to have in any community.

No one here is required to promptly reply or to reply at all to any post any user makes here.

If you hadn’t have a reply it may be because no one that saw this was in position of helping or was not having the time.

The correct attitude from you was to share the solution to your problem so that you can help someone else facing the same issue as you.

Do you like to find in the internet a topic about a problem your searching a solution for and then find a reply without a solution?

For example, like this one:

peterweyand

peterweyand OP

Never mind if anyone cared meant “if anyone is looking into this question then never mind I found the answer.” Sorry if that wasn’t more obvious. Didn’t mean to offend you. The solution is posted here: https://stackoverflow.com/questions/71574044/nginx-docker-compose-phoenix

Exadra37

Exadra37

On Stackoverflow you can mark your own answers as the accepted one. I have upvoted it.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews