Search code examples
websocketclojurewebserver

nginx prod setup for Clojure WebSocket app


I'm trying to deploy my first Clojure WebSocket app and I think I'm getting close. I get a good response locally, and it looks like the endpoint wants to face the outside world (I see that the port is open when I run netstat), but no response. I'm certain that I have something setup incorrectly in nginx.

I currently already host a few other websites on this server, just want to add the necessary config to get requests made to wss://domain.com:8001 to communicate with my app.

Here is the location entry I'm using now:

location / {
  proxy_pass http://localhost:8001;
  proxy_http_version 1.1;
  proxy_set_header Connection "";
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_redirect off;
  access_log /var/www/logs/test.access.log;
  error_log /var/www/logs/test.error.log;
}

Could anyone help point me in the right direction? My guess is that I actually have too much in the config, and what's there is probably not correct.

** EDIT: ** For interested parties, I put up my working config (based on Erik Dannenberg's answer) in a gist.


Solution

  • You are missing two more headers, a minimal working config:

    location  /  {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        # add the two below
        proxy_set_header Upgrade websocket;
        proxy_set_header Connection upgrade;
        # optional, but helpful if you run into timeouts
        proxy_read_timeout 86400;
    }