Access Jupyter Lab running on VPS from internet via browser

On a VPS I ran a dockerized Jupyter Lab that itself driven from project freqtrade. It is the docker-compose and Dockerfile : docker-compose.yml :

---
version: '3'
services:
  ft_jupyterlab:
    build:
      context: .
      dockerfile: docker/Dockerfile.jupyter
    restart: unless-stopped
    container_name: ft_jupyterlab
    ports:
      - "127.0.0.1:8888:8888"
    volumes:
      - "./user_data:/freqtrade/user_data"
    # Default command used when running `docker compose up`
    command: >
      jupyter lab --port=8888 --ip 0.0.0.0 --allow-root --NotebookApp.token=''

Dockerfile.jupyter :

FROM freqtradeorg/freqtrade:develop_plot

# Pin prompt-toolkit to avoid questionary version conflict
RUN pip install jupyterlab "prompt-toolkit<=3.0.36" jupyter-client --user --no-cache-dir

# Empty the ENTRYPOINT to allow all commands
ENTRYPOINT []

I want to access the Jupyter Lab from the internet via browser. So, I used Nginx as below:

server {
    listen 7000;
    server_name _;

    location / {
        proxy_pass http://localhost:8888;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Suppose that test.example.com is pointed to <vps_ip> . By navigating to http://test.example.com:7000 from another machine, just the title of “JupyterLab” shown. No any contents rendered in browser.

Also it is log:

[I 2024-02-06 06:18:07.626 ServerApp] 302 GET / (@172.27.0.1) 0.63ms

With your config, JupyterLab should be served at http://test.example.com:7000/lab. Starting jupyter-lab without any token is not recommended. As you are opening the nginx for internet, anyone will be able to access your Jupyterlab server. Use a token in jupyterlab command and then you will be prompted to use that token while access JupyterLab.

If it does not work, please post logs of JupyterLab. You should be able to access them using docker logs ft_jupyterlab on your VPS.

I found the problem. In docker-compose file in sections port mapping, 127.0.0.1 must be removed.
ports:
- “8888:8888”

so, the JupyterLab is accessible through http://<vps_ip>:8888 (without Nginx reverse proxy), but still the way using Nginx (http://<vps_ip>:7000) doesn’t work. The log is mentioned at the end of my main post.