Jupyterhub和nginx反向代理配置

时间:2017-08-21 12:48:25

标签: nginx jupyterhub

我正在尝试配置jupyterhub代理以将内容路由到my-host-ip/notebook,但我无法找到解决方案。

我正在使用以下Nginx配置:

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;

        }
    }

2 个答案:

答案 0 :(得分:2)

我通过在jupyterhub配置文件中使用以下选项来修复此问题:

# 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'

答案 1 :(得分:0)

仅当您的客户端计算机上具有其他代理配置(如果您在浏览器或操作系统上使用代理访问互联网)时,此答案才有效。此失败可能是由于您的公司/学校/电信提供商的代理管理不善造成的,其原因在here中进行了解释。

解决方案

设置一个自签名的ssl证书,以便websocket可以通过TLS / SSL连接建立隧道。由于您已经安装了Nginx,因此这非常容易。按照this guide at digital ocean快速设置免费的自签名ssl证书。

此外,您需要在nginx websocket配置中添加以下标头才能起作用。

proxy_set_header Origin ""
相关问题