Skip to content

Instantly share code, notes, and snippets.

@heesoo
Created July 14, 2019 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heesoo/0f13657dc3745c19cff55f582b70bd0b to your computer and use it in GitHub Desktop.
Save heesoo/0f13657dc3745c19cff55f582b70bd0b to your computer and use it in GitHub Desktop.
Nginx Reverse Proxy Subpath for Jupyter
# setting up upstream to Jupyter running on port 8889
upstream notebook {
server localhost:8889;
keepalive 32;
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name YOURDOMAIN.com; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location = /notebook {
rewrite ^/(.*)$ $1/ permanent;
}
location /notebook {
error_page 403 = @proxy_notebook;
deny 127.0.0.1;
allow all;
# set a webroot, if there is one
root /some-webroot;
try_files $uri @proxy_notebook;
}
location @proxy_notebook {
proxy_read_timeout 300s;
proxy_pass http://notebook;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ /notebook/api/kernels/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
location ~ /notebook/terminals/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/YOURDOMAIN.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/YOURDOMAIN.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = YOURDOMAIN.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name YOURDOMAIN.com;
return 404; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment