1

I'm running a nginx reverse proxy container which has two subdomains. I can't reach either of the pages because it always returns "the site can't be reached".

The proxy is on localhost and I added the subdomains to /etc/hosts.

When I try my configuration on nginx (installed on pc) everything works fine, but in the docker I get the refused connection. Another thing is when I try to check the logs they are empty, so I don't know where the problem lies.

This is my Dockerfile:

FROM nginx
COPY default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

This is my default.conf file:

server {
    listen 80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        proxy_pass http://10.10.1.54/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /rtsp-over-websocket {
        proxy_pass http://10.10.1.54;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }
    error_log /var/log/nginx/debug.log debug;
}

server {
    listen 80;
    server_name camera2.localhost;
   
     location / {
        proxy_pass http://10.10.1.53/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /rtsp-over-websocket {
        proxy_pass http://10.10.1.53;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

    error_log /var/log/nginx/debug2.log debug;
}

I also docker exec into the container and I can see that the default.conf is copied over, but again when I try to check the logs they are just empty.

Jatniel
  • 1,967
  • 2
  • 19
  • 27
bakeljouw
  • 11
  • 3
  • How are you running the container – Chris Doyle Apr 13 '23 at 15:07
  • docker run -d image-name. – bakeljouw Apr 13 '23 at 15:20
  • wont you need to map the host port to the container port like `docker run -d -p 80:80 image-name` otherwise how do you expect to reach the port inside the container from the host – Chris Doyle Apr 13 '23 at 18:51
  • that solved it. i thought that exposing the port in the dockerfile did the same thing – bakeljouw Apr 14 '23 at 09:33
  • As detailed on the dockerfile page `The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.` – Chris Doyle Apr 14 '23 at 22:19
  • https://docs.docker.com/engine/reference/builder/#expose – Chris Doyle Apr 14 '23 at 22:20

0 Answers0