How to configure IPython behind nginx in a subpath

2019-01-31 02:26发布

I've got nginx running handling all SSL stuff and already proxying / to a Redmine instance and /ci to a Jenkins instance.

Now I want to serve an IPython instance on /ipython through that very same nginx.

In nginx.conf I've added:

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;
        }
    }
}

In my .ipython/profile_nbserver/ipython_notebook_config.py I've got:

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/'}

Pointing my browser to https://myserver/ipython gives me the usual index page of all notebooks in the directory I launched IPython.
However, when I try to open one of the existing notebooks or create a new one, I'm getting the error:

WebSocket connection failed: A WebSocket connection to could not be established. You will NOT be able to run code. Check your network connection or notebook server configuration.

I've tried the same setup with the current stable (1.2.1, via pypi) and development (Git checkout of master) version of IPython.
I also tried adjusting the nginx config according to nginx reverse proxy websockets with no avail.
Due to an enforced policy I'm not able to allow connections to the server on other ports than 443.

Does anybody have IPython running behind an nginx?

1条回答
爷、活的狠高调
2楼-- · 2019-01-31 02:45

I had the same problem. I updated nginx up to the current version (1.6.0). It seems to be working now.

Server config:

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 "";
}

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

查看更多
登录 后发表回答