Skip to content

Instantly share code, notes, and snippets.

@SamuelMarks
Created September 3, 2022 19:26
Show Gist options
  • Save SamuelMarks/955d146ab20a06a2e6e67df6ce422557 to your computer and use it in GitHub Desktop.
Save SamuelMarks/955d146ab20a06a2e6e67df6ce422557 to your computer and use it in GitHub Desktop.
nginx conf for Jupyter Notebook
# /etc/nginx/sites-enabled/DOMAIN.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name DOMAIN_NAME;
return 302 https://$host$request_uri;
}
server {
listen 443;
ssl on;
server_name DOMAIN_NAME;
ssl_certificate /etc/letsencrypt/live/DOMAIN_NAME/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/DOMAIN_NAME/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Scheme $scheme;
proxy_buffering off;
}
# Managing requests to verify letsencrypt host
location ~ /.well-known {
allow all;
}
}
# /lib/systemd/system/jupyter_notebook.service
[Unit]
Description=Job that runs the jupyter_notebook daemon
[Service]
User=VIRTUALENV_USER
Group=VIRTUALENV_GROUP
Environment=VIRTUALENV=VIRTUALENV_BIN
Environment=PYTHONPATH=VIRTUALENV_BIN
WorkingDirectory=/MY/NOTEBOOKS/DIR
ExecStart=VIRTUALENV_BIN/jupyter notebook --no-browser --NotebookApp.port=8000 --NotebookApp.notebook_dir=/MY/NOTEBOOKS/DIR --NotebookApp.local_hostnames DOMAIN --NotebookApp.allow_origin DOMAIN --NotebookApp.password_required=True --NotebookApp.password argon2:$argon2id$v=19$m=1024<omitted>
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment