nginx-proxy: Websocket connection can't be made

I’m trying to run an instance of Jupyter on my Digital Ocean server using this container: https://hub.docker.com/r/jupyter/notebook/. I have nginx-proxy configured to connect to that container with the correct hostname, but despite editing the notes.rooday.com_location file in /etc/nginx/vhost.d/, websocket connections can’t be made.

This is my notes.rooday.com_location file:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;

This is the error Chrome gives me when I open a jupyter iPython notebook and attempt to make a websocket connection:

WebSocket connection to 'ws://notes.rooday.com/api/kernels/677b0d97-20cd-4b1a-b499-c9b513b859d9/channels?session_id=6E236819286E46D38B03D34047252F48' failed: Error during WebSocket handshake: Unexpected response code: 400

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 28

Most upvoted comments

Very strange, this my dump when it works:

$ docker run -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
$ docker run --rm -e VIRTUAL_HOST=docker-machine jupyter/notebook
$ docker exec desperate_torvalds cat /etc/nginx/conf.d/default.conf
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
access_log off;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
}
upstream docker-machine {
            # boring_sinoussi
            server 172.17.0.9:8888;
}
server {
    server_name docker-machine;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://docker-machine;
    }
}