Skip to content

Commit

Permalink
Support http-configurable and nginx reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
hungdinhxuan committed Nov 20, 2023
1 parent e31f3a5 commit 7330500
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
27 changes: 23 additions & 4 deletions basic-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# JupyterHub docker-compose configuration file
version: "3"

services:
Expand Down Expand Up @@ -36,6 +32,29 @@ services:
# Notebook directory inside user image
DOCKER_NOTEBOOK_DIR: /home/jovyan/work

proxy:
image: jupyterhub/configurable-http-proxy:4.6.0
container_name: jupyterhub-proxy
restart: always
networks:
- jupyterhub-network
ports:
- "8002:8000"
command: ["--default-target=http://hub:8000"]

reverse-proxy:
image: nginx:1.25.3
container_name: jupyterhub-reverse-proxy
restart: always
networks:
- jupyterhub-network
ports:
- "8001:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- proxy

volumes:
jupyterhub-data:

Expand Down
1 change: 1 addition & 0 deletions basic-example/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
# Allow anyone to sign-up without approval
c.NativeAuthenticator.open_signup = True


# Allowed admins
admin = os.environ.get("JUPYTERHUB_ADMIN")
if admin:
Expand Down
26 changes: 26 additions & 0 deletions basic-example/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
events {
worker_connections 1024;
}

http {
server {
listen 80;

location / {
proxy_pass http://proxy:8000; # Assuming 'proxy' is the service name in docker-compose

# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

# Handling real IP and scheme in proxied server
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 X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
}

0 comments on commit 7330500

Please sign in to comment.