【问题标题】:How to configure IPython behind nginx in a subpath?如何在子路径中的 nginx 后面配置 IPython?
【发布时间】:2014-05-05 03:20:34
【问题描述】:

我已经让 nginx 运行处理所有 SSL 内容,并且已经将 / 代理到 Redmine 实例,并将 /ci 代理到 Jenkins 实例。

现在我想通过同样的 nginx/ipython 上提供一个 IPython 实例。

nginx.conf我已经添加:

http {
    ...
    upstream ipython_server {
        server 127.0.0.1:5001;
    }

    server {
        listen 443 ssl default_server;
        ... # all SSL related stuff and the other proxy configs (Redmine+Jenkins)

        location /ipython {
            proxy_pass http://ipython_server;
        }
    }
}

在我的.ipython/profile_nbserver/ipython_notebook_config.py 我有:

c.NotebookApp.base_project_url = '/ipython/'
c.NotebookApp.base_kernel_url = '/ipython/'
c.NotebookApp.port = 5001
c.NotebookApp.trust_xheaders = True
c.NotebookApp.webapp_settings = {'static_url_prefix': '/ipython/static/'}

将我的浏览器指向https://myserver/ipython 会显示我启动的目录中所有笔记本的常用索引页IPython
但是,当我尝试打开一个现有笔记本或创建一个新笔记本时,我收到了错误:

WebSocket 连接失败无法建立 WebSocket 连接。您将无法运行代码。检查您的网络连接或笔记本服务器配置。

我已经尝试了与当前稳定版(1.2.1,通过 pypi)和开发(Git checkout of master)版本的 IPython 相同的设置。
我还尝试根据nginx reverse proxy websockets调整nginx配置,但无济于事。
由于强制执行的政策,我无法允许在 443 以外的其他端口上连接到服务器。

有人在 nginx 后面运行 IPython 吗?

【问题讨论】:

  • 你用的是什么版本的 NGINX?
  • 我刚刚在我的 Ubuntu 服务器上遇到了完全相同的问题。我运行的是 Ubuntu 12.04,NGINX 的版本是 1.1.19。环顾四周,似乎 websockets 代理转发直到 NGINX 中的 1.3.something 才得到解决。所以我按照本指南:usefulmix.com/… 升级 NGINX(在我的情况下,我现在运行的是 1.5.13)。之后一切都很顺利。

标签: nginx proxy websocket ipython


【解决方案1】:

我遇到了同样的问题。我将 nginx 更新到当前版本(1.6.0)。它现在似乎可以工作了。

服务器配置:

location /ipython {
    proxy_pass http://ipython_server;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Origin "";
}

见:http://nginx.org/en/docs/http/websocket.html

【讨论】:

  • 我必须添加 proxy_set_header Origin ""; 才能完成这项工作。 Tornado 服务器不接受其他连接,因为源检查未通过。
  • ^^^ 这个评论很关键!
  • 那么我该如何处理由于我正在进行跨域调用而需要传递Origin 标头的情况?
  • 我不知道为什么,但这也对我有用。可以从文档中跟踪我的配置中的所有内容,但是在访问笔记本时我仍然得到 404,直到我对我的 nginx 配置进行了更改
  • 今天仍然有效
猜你喜欢
  • 2014-09-26
  • 2021-12-08
  • 1970-01-01
  • 2015-12-14
  • 2017-09-24
  • 2015-10-20
  • 1970-01-01
  • 2016-11-04
  • 2012-08-05
相关资源
最近更新 更多