skip to Main Content

Hello I want to say right away that I have been using docker-compose and nginx for not so long, sorry if you’ll see some mistakes from my own. M

I am facing with problem with nginx settings and can’t solve it for a couple of days now. My task is to use docker-compose to connect to another container on my local comp. In first container I use reverse proxy, forwarding my requests to another container with running Jupyterlab. But I always get 502 Bad Gateway when I connect to Jupyter, but these two containers running.
Maybe it not necessary with Jupyter, but with app in reverse proxy

I assume the problem is with my docker-compose network, but I used different ways, but unfortunately I always have the same problem

So my docker-compose looks like this

version: '3.8'

services:
    jupyterlab:
        build:
            ...
        volumes:
            - ...
        ports:
            - "8888:8888"
        networks:
            - new-networks


    nginx:
        build:
            ...
        ports:
            - "80:80"
        networks:
            - new-networks
networks:
    new-networks:
        driver: bridge
        ipam:
            driver: default
            config:
                - subnet: 127.0.0.0/16

In Dockerfile of jupyter I have EXPOSE 8888

In nginx container I use sites-enable with a file named domain (so 127.0.0.1), not nginx.conf (but in some ways in this task I used nginx.conf too, but I’ve got the same error)

My settings in nginx (file name: 127.0.0.1):

upstream backend {
        server 127.0.0.1:8888;
}

server {
        listen 80;
        listen [::]:80;

        root /var/www/127.0.0.1/html;
        index index.html index.htm index.nginx-debian.html;

        server_name 127.0.0.1 www.127.0.0.1 ;


        location /jupyter {
                proxy_pass http://backend/;
        }

        location /status {
                default_type application/json;
                return 200 '{"status": "All good"}';
        }
}

I’ve tried using another domain (like 172…) in upstream and in proxy_pass. Tried set_headers. Change ufw (but not so much). But it’s always the same error (502).

I’ve checked my logs in nginx (if in upstream I write 127.0.0.1:8888) and it get:

connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: 127.0.0.1, request: "GET /jupyter HTTP/1.1", upstream: "http://127.0.0.1:8888/", host: "127.0.0.1"

Logs when I write 172…:8888 un upstream (here I got 404 error):

*2 open() "/var/www/127.0.0.1/html/lab" failed (2: No such file or directory), client: 172.18.0.1, server: 127.0.0.1, request: "GET /lab? HTTP/1.1", host: "127.0.0.1"

upd.2

Also I’ve tried to use:

upstream backend {
        server jupyterlab:8888;

But I only get 404

*6 open() "/var/www/127.0.0.1/html/lab" failed (2: No such file or directory), client: 172.20.0.1, server: 127.0.0.1, request: "GET /lab? HTTP/1.1", host: "127.0.0.1"

upd.3

Now I changed my nginx conf file, and now get another 404 not as usual.

upstream jupyter {
        server jupyterlab:8888;
}

server {
        listen nginx:80;

        server_name 127.0.0.1 www.127.0.0.1 ;


        location /jupyter {
                proxy_pass http://jupyter;
        }

        location /ping {
                default_type application/json;
                return 200 '{"status": "All good"}';
        }
}

In log file I got new errors:

2023/11/01 12:52:08 [error] 25#25: *3 open() "/usr/share/nginx/html/static/style/index.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/index.css?v=30372e3246a801d662cf9e3f9dd656fa192eebde9054a2282449fe43919de9f0ee9b745d7eb49d3b0a5e56357912cc7d776390eddcab9dac85b77bdb17b4bdae HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 26#26: *2 open() "/usr/share/nginx/html/static/style/bootstrap-theme.min.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/bootstrap-theme.min.css?v=8b2f045cb5b4d5ad346f6e816aa2566829a4f5f2783ec31d80d46a57de8ac0c3d21fe6e53bcd8e1f38ac17fcd06d12088bc9b43e23b5d1da52d10c6b717b22b3 HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 26#26: *1 open() "/usr/share/nginx/html/static/style/bootstrap.min.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/bootstrap.min.css?v=0e8a7fbd6de23ad6b27ab95802a0a0915af6693af612bc304d83af445529ce5d95842309ca3405d10f538d45c8a3a261b8cff78b4bd512dd9effb4109a71d0ab HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 27#27: *4 open() "/usr/share/nginx/html/static/style/index.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/index.css?v=30372e3246a801d662cf9e3f9dd656fa192eebde9054a2282449fe43919de9f0ee9b745d7eb49d3b0a5e56357912cc7d776390eddcab9dac85b77bdb17b4bdae HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 25#25: *3 open() "/usr/share/nginx/html/static/logo/logo.png" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/logo/logo.png?v=a2a176ee3cee251ffddf5fa21fe8e43727a9e5f87a06f9c91ad7b776d9e9d3d5e0159c16cc188a3965e00375fb4bc336c16067c688f5040c0c2d4bfdb852a9e4 HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 26#26: *2 open() "/usr/share/nginx/html/static/style/bootstrap-theme.min.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/bootstrap-theme.min.css?v=8b2f045cb5b4d5ad346f6e816aa2566829a4f5f2783ec31d80d46a57de8ac0c3d21fe6e53bcd8e1f38ac17fcd06d12088bc9b43e23b5d1da52d10c6b717b22b3 HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 25#25: *3 open() "/usr/share/nginx/html/static/style/bootstrap.min.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/bootstrap.min.css?v=0e8a7fbd6de23ad6b27ab95802a0a0915af6693af612bc304d83af445529ce5d95842309ca3405d10f538d45c8a3a261b8cff78b4bd512dd9effb4109a71d0ab HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 26#26: *2 open() "/usr/share/nginx/html/static/style/bootstrap-theme.min.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/bootstrap-theme.min.css?v=8b2f045cb5b4d5ad346f6e816aa2566829a4f5f2783ec31d80d46a57de8ac0c3d21fe6e53bcd8e1f38ac17fcd06d12088bc9b43e23b5d1da52d10c6b717b22b3 HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 27#27: *4 open() "/usr/share/nginx/html/static/style/index.css" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/style/index.css?v=30372e3246a801d662cf9e3f9dd656fa192eebde9054a2282449fe43919de9f0ee9b745d7eb49d3b0a5e56357912cc7d776390eddcab9dac85b77bdb17b4bdae HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/01 12:52:08 [error] 26#26: *1 open() "/usr/share/nginx/html/static/logo/logo.png" failed (2: No such file or directory), client: 172.24.0.1, server: 127.0.0.1, request: "GET /static/logo/logo.png?v=a2a176ee3cee251ffddf5fa21fe8e43727a9e5f87a06f9c91ad7b776d9e9d3d5e0159c16cc188a3

If I transition in Jupyter server, I will get basic 404 error. And logs will look like these:

2023/11/02 11:15:54 [error] 25#25: *2 open() "/usr/share/nginx/html/lab" failed (2: No such file or directory), client: 172.25.0.1, server: 127.0.0.1, request: "GET /lab HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/jupyter"
2023/11/02 11:15:54 [error] 25#25: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.25.0.1, server: 127.0.0.1, request: "GET /favicon.ico HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.14/lab"
2023/11/02 11:19:37 [error] 24#24: *3 open() "/usr/share/nginx/html/lab" failed (2: No such file or directory), client: 172.25.0.1, server: 127.0.0.1, request: "GET /lab HTTP/1.1", host: "196.172.12.14", referrer: "http://196.172.12.144/jupyter"

I’d appreciate for any help

2

Answers


  1. Chosen as BEST ANSWER

    Anyway I close this question, now I have a different problem, not as written in this topic.

    The problem was in my nginx conf, where the slashes were misplaced and the path was not completely spelled out. As @Andromeda said I need to use service name in my upstream. And in location I have to use more detailed path with slashes.

    upstream jupyter {
            server jupyterlab:8888;
    }
    
    server {
            listen nginx:80;
    
            server_name 127.0.0.1 www.127.0.0.1 ;
    
    
            location /jupyter/ {
                    proxy_pass http://jupyter/lab/;
            }
    
            location /ping {
                    default_type application/json;
                    return 200 '{"status": "All good"}';
            }
    }
    

  2. upstream backend {
            server jupyterlab:8888;
    }
    

    Should solve the problem.
    In docker-compose services are discoverable using services` name.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search