vital987 / chrome-novnc

Chromium via noVNC (Browser in Browser)
MIT License
102 stars 56 forks source link

Reverse Proxy via Nginx #11

Closed cry0genic closed 2 months ago

cry0genic commented 3 months ago

Hey @vital987, sorry to trouble you again. When I'm trying to reverse proxy the current setup via Nginx, I'm getting an error with code 1006.

Can you help me figure out why this is happening and if possible help resolve this?

Here's the code I'm trying:

docker-compose:

version: '3.4'

services:
  chrome-novnc:
    container_name: chrome-novnc
    environment:
      - VNC_PASS=${VNC_PASS-CHANGE_IT}
      - VNC_TITLE=${VNC_TITLE-Chromium}
      - VNC_SHARED=${VNC_SHARED-false}
      - VNC_RESOLUTION=${VNC_RESOLUTION-1280x720}
      - PORT=8080
    image: vital987/chrome-novnc:latest
    ports:
      - "${HOST_PORT-8080}:8080/tcp"
    restart: always
  nginx:
    container_name: nginx
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 1337:80
    volumes:
      - ./nginx:/etc/nginx/conf.d
    depends_on:
      - chrome-novnc

./nginx/nginx.conf:

upstream chrome-novnc {
    server chrome-novnc:8080;
}

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

    location / {
        proxy_pass http://chrome-novnc;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

Then I'm going to http://localhost:1337/?password=CHANGE_IT

Thanks!

cry0genic commented 3 months ago

Hey @vital987, following up on this, any chance you can help me out here?

Thanks!

cry0genic commented 3 months ago

Hey @vital987, following up, do let me know if you can help me out here.

Thanks!

vital987 commented 3 months ago

Hello @cry0genic, apologies for the delay, currently am busy in some other work. I will follow up after getting free.

cry0genic commented 2 months ago

Hey @vital987, if you're free now do check this issue out. Thanks!

vital987 commented 2 months ago

Hey, upon using reverse proxy, I was able to get the web-ui screen but wasn't able to connect to websockify, the issue is, websockify uses client host URL to connect to it's websocket endpoint and upon reverse proxying, it picks up the address of nginx server and tries to connect to ws://nginx-server/websockify, which isn't the case, hence I don't think it's easily posible.

The direct connection, running on port 8080

normal

Using reverse proxy, running on port 80

fail

cry0genic commented 2 months ago

This fixed it:

nginx conf:


# nginx/nginx.conf
upstream chrome {
    server chrome-novnc:8080;
}

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

    location / {
        proxy_pass http://chrome;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

and

docker-compose.yml:

version: '3.4'

services:
  chrome-novnc:
    container_name: chrome-novnc
    environment:
      - VNC_PASS=${VNC_PASS-CHANGE_IT}
      - VNC_TITLE=${VNC_TITLE-Chromium}
      - VNC_SHARED=${VNC_SHARED-true}
      - VNC_RESOLUTION=${VNC_RESOLUTION-1280x720}
      - PORT=8080
    image: vital987/chrome-novnc:latest
    expose:
      - 8080
    ports:
      - "${HOST_PORT-8080}:8080/tcp"
      - "4444:4444"
    restart: always
    networks:
      - streaming
    shm_size: 3g
  nginx:
    container_name: nginx
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 80:80
    volumes:
      - ./nginx:/etc/nginx/conf.d
    depends_on:
      - chrome-novnc
    networks:
      - streaming

networks:
  streaming:
    external: true