jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.72k stars 4.96k forks source link

Nginx Jupyter notebook with sub location doesn't work #2843

Open JeremyLG opened 7 years ago

JeremyLG commented 7 years ago

Here is my Nginx conf :

location /jupyter/ {

proxy_pass http://10.33.1.164:8888; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; rewrite ^/jupyter/(.*)$ /$1 break; } location /(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/? { proxy_pass http://10.33.1.164:8888; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

WebSocket support

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
    }

So when I go to my domain.com/jupyter, it redirects me to mydomain.com/tree? and from there it is 404 error code, what am I doing wrong ?

tHank !

jcrubino commented 7 years ago

try

location ~* /ipy/(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/?

~* seems to be missing in you config

JeremyLG commented 7 years ago

I tried your idea with location ~* /jupyter/(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/?

But this still gives me the same 404 error error_nginx

AnthonyLELUYER commented 4 years ago

Hi,

Old issue, should be fixed by now, however I just fixed it. I had exactly the same Nginx configuration as JeremyLG, here is how I fixed it:

    location /notebooks/ {
        proxy_set_header Host $host;
        proxy_pass http://localhost:5001;
    }

    location ~* /notebooks/(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/? {
        proxy_pass http://localhost:5001;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade "websocket";
        proxy_set_header Connection "Upgrade";
    }

My Jupyter notebook server is working with these parameters:

c.NotebookApp.allow_origin = '*'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.base_url = '/notebooks'
c.NotebookApp.ip = 'localhost'
c.NotebookApp.open_browser = False
c.NotebookApp.password = '[[ YOUR_HASHED_PASSWORD ]]' # optional
c.NotebookApp.port = 5001
c.NotebookApp.trust_xheaders = True