21

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?

Community
  • 1
  • 1
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
  • What version of NGINX are you using? – 8one6 Apr 17 '14 at 21:37
  • I just had the exact same problem on my Ubuntu server. I was running Ubuntu 12.04 and the version of NGINX was 1.1.19. Looking around it seemed like the websockets proxy forwarding didn't get sorted out until 1.3.something in NGINX. So I followed this guide: http://usefulmix.com/install-upgrade-to-latest-nginx-without-compiling-from-source/ to get NGINX upgraded (in my case I'm now running 1.5.13). Everything worked perfectly afterwards. – 8one6 Apr 17 '14 at 21:41

1 Answers1

30

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

Community
  • 1
  • 1
iroln
  • 1,116
  • 1
  • 16
  • 16