nginx

Jupyter notebook refuse to work with nginx


I use nginx to proxy jupyter.mysite.com to localhost:8888.

If I enter mysite.com:8888, the kernel works well! But if I enter jupyter.mysite.com, Jupyter Notebook will not find a kernel!

Ing1. Kernel error

Here is something about the configuration.

[suzu@kusanagi71 ~]$ jupyter kernelspec list                    
Available kernels:                                                                              
  python3    /home/suzu/.local/share/jupyter/kernels/python3                                    
[suzu@kusanagi71 ~]$ whereis python3                                                            
python3: /usr/bin/python3 /usr/local/bin/python3.7m /usr/local/bin/python3.7 /usr/local/bin/python3.7m-config /usr/local/bin/python3 /usr/local/bin/python3.7-config /usr/local/lib/python3.7 /usr/local/python3                                                                                
[suzu@kusanagi71 ~]$ cd /home/suzu/.local/share/jupyter/kernels/python3                         
[suzu@kusanagi71 python3]$ ll                                                                   
合計 12                                                                                         
-rw-rw-r-- 1 suzu suzu  156 10月 30 13:55 kernel.json                                           
-rw-r--r-- 1 suzu suzu 1084 10月 30 11:11 logo-32x32.png                                        
-rw-r--r-- 1 suzu suzu 2180 10月 30 11:11 logo-64x64.png                                        
[suzu@kusanagi71 python3]$ nano kernel.json                                                     
[suzu@kusanagi71 python3]$  

Img2. kernel json

Here is my conf file of nginx:

[suzu@kusanagi71 ~]$ cat /etc/nginx/conf.d/jupyter.mysite.com.conf    

#=======================================
# jupyter.mysite.com
#---------------------------------------

server {
    listen      8080;
    server_name jupyter.mysite.com;
    charset     utf-8;

    client_max_body_size 75M;

    location / {
        proxy_pass  http://127.0.0.1:8888;
        include     /etc/nginx/uwsgi_params;
    }
}

And by the way, because I lived in China, I have the shadowsocks listened to 80 port, if the request is not a shadowsocks request, it just throw it to 8080 nginx port.

So it could be really complicated.

I don't know why it doesn't work with nginx...

But I could use 8888 to access it now.


Solution

  • Finally I found the solution!!! Because jupyter need the nginx to have websocket, so it will not work if you are using a general backproxy.

    location / 
    {
        proxy_pass http://192.168.91.138:18882;
        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 REMOTE-HOST $remote_addr;
    
        #缓存相关配置
        #proxy_cache cache_one;
        #proxy_cache_key $host$request_uri$is_args$args;
        #proxy_cache_valid 200 304 301 302 1h;
    
        #持久化连接相关 WebSocket 配置
        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";        
        expires 12h;
    }