4

I was trying to configure the jupyterhub proxy to route the content going to my-host-ip/notebook but it i cannot figure out the solution.

I am using the following Nginx configuration:

server {
        listen 80;
        server_name  localhost;

        location /notebook {
            proxy_pass http://localhost:8000;

            # proxy_set_header X-Real-IP $remote_addr;
            # proxy_set_header Host $http_host;
            # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location ~* /(user[-/][a-zA-Z0-9]*)/(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/? {
            proxy_pass http://localhost:8000;

            # proxy_set_header X-Real-IP $remote_addr;
            # proxy_set_header Host $http_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_read_timeout 86400;

        }
    }
ziedTn
  • 262
  • 5
  • 17
  • Did you check this? https://aptro.github.io/server/architecture/2016/06/21/Jupyter-Notebook-Nginx-Setup.html – Tarun Lalwani Aug 21 '17 at 12:52
  • @TarunLalwani do you mean using the same approach because i am using jupyterhub that encapsulate jupyter notebook – ziedTn Aug 21 '17 at 12:57

2 Answers2

3

I fixed this by using the following options with jupyterhub configuration file:

# Force the proxy to only listen to connections to 127.0.0.1 
c.JupyterHub.ip = '127.0.0.1'  
c.JupyterHub.base_url = u'/notebook'
ziedTn
  • 262
  • 5
  • 17
1

This answer is valid only if you have another proxy configuration on your client computer ( if you are using a proxy on your browser or os to access the internet). This failure could be due to a poorly managed proxy by your company/school/telecom provider, reasons explained in here.

Solution

setup a self signed ssl certificate so that the websocket can tunnel through the TLS/SSL connection. Since you already have Nginx installed this is quite easy. Follow this guide at digital ocean to quickly setup a free self signed ssl certificate.

Further you need to add the following header in your nginx websocket config to work.

proxy_set_header Origin ""
Gayan Kavirathne
  • 2,909
  • 2
  • 18
  • 26