Skip to content

Instantly share code, notes, and snippets.

@cboettig
Created December 31, 2015 18:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cboettig/18e1becaa8974139adff to your computer and use it in GitHub Desktop.
Save cboettig/18e1becaa8974139adff to your computer and use it in GitHub Desktop.
Caddyserver proxy for Jupyter
https://example.com {
proxy / jupyter:8888 {
proxy_header X-Real-IP {remote}
proxy_header Host {host}
}
proxy {{.PathMatches "~* /(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/?"}} jupyter:8888 {
proxy_header X-Real-IP {remote}
proxy_header Host {host}
websocket
}
}
jupyter:
image: jupyter/minimal-notebook
environment:
- PASSWORD=${PASSWORD}
caddy:
image: joshix/caddy
links:
- jupyter
volumes:
- .:/var/www/html
- $HOME/.caddy/:/.caddy
ports:
- 80:80
- 443:443
@jcrubino
Copy link

An up-to-date Caddyfile for Jupyter Notebooks

example.com {

proxy / localhost:8888 {
header_upstream X-Real-IP {remote}
header_upstream Host {host}
}

rewrite {
    r "~* /(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/?"
    to /proxy/{uri}
}
proxy /proxy/ localhost:8888 {
    header_upstream X-Real-IP {remote}
    header_upstream Host {host}
    websocket
    without /proxy/
}

}`

Still needs fixes for design purposes, but functions.

@syu-id
Copy link

syu-id commented Nov 9, 2018

I tried this with JupyterLab 0.35.4 and Caddy 0.11.0 but it didn't work well.
The terminal won't show up and the Python console won't return any results

An up-to-date Caddyfile for Jupyter Notebooks

example.com {

proxy / localhost:8888 {
header_upstream X-Real-IP {remote}
header_upstream Host {host}
}

rewrite {
    r "~* /(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/?"
    to /proxy/{uri}
}
proxy /proxy/ localhost:8888 {
    header_upstream X-Real-IP {remote}
    header_upstream Host {host}
    websocket
    without /proxy/
}

}`

Still needs fixes for design purposes, but functions.

@kebot
Copy link

kebot commented May 6, 2019

Update, test with latest jupyter and caddy use docker

# /etc/caddy/Caddyfile
www.yourdomain.com:80, www.yourdomain.com:443 {
    tls youremail@126.com
    gzip
    proxy / localhost:10088 {
        header_upstream Connection {>Connection}
        header_upstream Upgrade {>Upgrade}
        header_upstream Host {host}
        header_upstream X-Real-IP {remote}
        header_upstream X-Forwarded-For {remote}
        header_upstream X-Forwarded-Proto {scheme}
    }
}

@naviat
Copy link

naviat commented May 24, 2019

@kebot what's about for rewrite expression?

@colinaaa
Copy link

@cboettig
Copy link
Author

Thanks @colinaaa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment