From a5688c071dd9e57419fa01e13260dbc2742023ed Mon Sep 17 00:00:00 2001
From: DerGrumpf
Date: Mon, 15 Sep 2025 16:19:07 +0200
Subject: [PATCH] Added: Changed Nginx
---
jupyterhub/jupyterhub_config.py | 6 ++--
nginx/compose.yml | 4 +--
nginx/conf.d/jupyterhub.conf | 55 ++++++++++++++++---------------
nginx/nginx.conf | 42 +++++++++++++----------
nginx/snippets/proxy-headers.conf | 9 -----
5 files changed, 56 insertions(+), 60 deletions(-)
delete mode 100644 nginx/snippets/proxy-headers.conf
diff --git a/jupyterhub/jupyterhub_config.py b/jupyterhub/jupyterhub_config.py
index 7676a7f..431eeef 100644
--- a/jupyterhub/jupyterhub_config.py
+++ b/jupyterhub/jupyterhub_config.py
@@ -66,7 +66,7 @@ base_url = os.environ.get("JUPYTERHUB_BASE_URL", "/jupyter/")
c.JupyterHub.bind_url = f"http://0.0.0.0:{port}{base_url}"
# Database configuration
-c.JupyterHub.db_url = f"postgresql://{os.environ['POSTGRES_USER']}:{os.environ['POSTGRES_PASSWORD']}@stack-{os.environ['POSTGRES_HOST']}:5432/{os.environ['POSTGRES_DB']}"
+c.JupyterHub.db_url = f"postgresql://{os.environ['POSTGRES_USER']}:{os.environ['POSTGRES_PASSWORD']}@{os.environ['POSTGRES_HOST']}:5432/{os.environ['POSTGRES_DB']}"
# c.JupyterHub.db_url = 'sqlite:///jupyterhub.sqlite'
@@ -100,9 +100,7 @@ c.JupyterHub.template_paths = ["/etc/jupyterhub/templates"]
c.JupyterHub.spawner_class = DockerSpawner
# Spawn Containers from this Image
-c.DockerSpawner.image = os.environ.get(
- "NOTEBOOK_IMAGE", "jupyter/scipy-notebook:latest"
-)
+c.DockerSpawner.image = os.environ.get("NOTEBOOK_IMAGE", "jupyter/base-notebook:latest")
# Connect Containers to this network
network_name = os.environ.get("DOCKER_NETWORK_NAME", "stack_default")
diff --git a/nginx/compose.yml b/nginx/compose.yml
index 7ef741f..81094e7 100644
--- a/nginx/compose.yml
+++ b/nginx/compose.yml
@@ -9,7 +9,5 @@ services:
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./conf.d:/etc/nginx/conf.d:ro
- - ./snippets:/etc/nginx/snippets:ro
- ./ssl:/etc/nginx/ssl:ro
- - ../logs/nginx:/etc/log/nginx
- - ./discord.html:/var/www/static/index.html:ro
+ - ../logs/nginx:/var/log/nginx
diff --git a/nginx/conf.d/jupyterhub.conf b/nginx/conf.d/jupyterhub.conf
index 343ed98..cb48e03 100644
--- a/nginx/conf.d/jupyterhub.conf
+++ b/nginx/conf.d/jupyterhub.conf
@@ -1,43 +1,44 @@
-# Shared proxy headers
-include /etc/nginx/snippets/proxy-headers.conf;
-
+# nginx/conf.d/jupyterhub.conf
server {
- listen 80 default_server;
- server_name _;
-
+ listen 80;
+ server_name _; # Respond to all hostnames
+
+ # JupyterHub with base URL /jupyter/
location /jupyter/ {
- proxy_pass http://jupyterhub:8000/; # Docker service name
+ proxy_pass http://jupyterhub:8000/jupyter/;
+ proxy_set_header Host $host;
+ 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;
- # Apply shared proxy headers
- include /etc/nginx/snippets/proxy-headers.conf;
-
- # Special WebSocket timeout
+ # WebSocket support (crucial for Jupyter)
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
+
+ # Handle large file uploads
+ client_max_body_size 100M;
+ proxy_request_buffering off;
}
- # Redirect /jupyter to /jupyter/
- location = /jupyter {
+ # Redirect root to JupyterHub
+ location = / {
return 302 /jupyter/;
}
-
- # Stativ site conf
- root /var/www/static;
- index index.html;
-
- location / {
- try_files $uri $uri/ =404;
- }
-
- # Cache static assets
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
- expires 30d;
- add_header Cache-Control "public, no-transform";
+ # Health check endpoint
+ location /jupyter/hub/health {
+ proxy_pass http://jupyterhub:8000/jupyter/hub/health;
+ proxy_set_header Host $host;
+ access_log off;
+ allow all;
}
# Deny access to hidden files
location ~ /\. {
deny all;
+ access_log off;
+ log_not_found off;
}
-
}
diff --git a/nginx/nginx.conf b/nginx/nginx.conf
index d026952..4a3f652 100644
--- a/nginx/nginx.conf
+++ b/nginx/nginx.conf
@@ -1,30 +1,38 @@
-user nginx;
-worker_processes auto;
-
-error_log /var/log/nginx/error.log warn;
-pid /var/run/nginx.pid;
+user nginx;
+worker_processes auto;
+error_log /var/log/nginx/error.log warn;
+pid /var/run/nginx.pid;
events {
- worker_connections 1024;
+ worker_connections 1024;
}
http {
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
+ include /etc/nginx/mime.types;
+ default_type application/octet-stream;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
+ # Log format
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
+ '$status $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /var/log/nginx/access.log main;
+ access_log /var/log/nginx/access.log main;
- sendfile on;
- keepalive_timeout 65;
+ # Basic settings
+ sendfile on;
+ tcp_nopush on;
+ tcp_nodelay on;
+ keepalive_timeout 65;
+ types_hash_max_size 2048;
# Gzip compression
- gzip on;
- gzip_types text/plain text/css application/json application/javascript text/xml;
+ gzip on;
+ gzip_vary on;
+ gzip_min_length 1024;
+ gzip_types text/plain text/css text/xml text/javascript
+ application/json application/javascript application/xml+rss
+ application/atom+xml image/svg+xml;
- # Include modular configs
+ # Include server configurations
include /etc/nginx/conf.d/*.conf;
}
diff --git a/nginx/snippets/proxy-headers.conf b/nginx/snippets/proxy-headers.conf
deleted file mode 100644
index ffbd5be..0000000
--- a/nginx/snippets/proxy-headers.conf
+++ /dev/null
@@ -1,9 +0,0 @@
-proxy_set_header Host $host;
-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;
-
-# WebSocket support
-proxy_http_version 1.1;
-proxy_set_header Upgrade $http_upgrade;
-proxy_set_header Connection "upgrade";