title: How do I configure nginx for WSS usage on a spark-core Websocket server?
body: <p>I am hosting a webserver for a project. There are endpoints for all the frontend content at <code>/*</code>, resources at <code>/resources/*</code> and then I wish to add a WebSocket server as well at <code>/chatterbox/api/connect/</code>. I am running this all using a <code>spark-core</code> server. I am using nginx to proxy all of this and this is what is causing the issue. It works fine localhost without the need for HTTPS, but my nginx config messes something up.</p>
  <p>This is my config:</p>
  <pre><code>server {
      if ($host = sub.domain.xyz) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
  
      listen 80;
      server_name sub.domain.xyz;
      return 301 https://$server_name$request_uri;
  
  }
  
  map $http_upgrade $connection_upgrade {
      default Upgrade;
      '' close;
  }
  
  server {
      server_name sub.domain.xyz;
      listen 443 ssl;
  
      location / {
          proxy_pass http://127.0.0.1:1525;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $http_host;
          proxy_set_header X-Forwarded-Proto https;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
      }
  
      location /chatterbox/api/connect/ {
          proxy_pass http://127.0.0.1:1525/chatterbox/api/connect/;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
          proxy_set_header Host $host;
      }
  
      ssl_certificate /etc/letsencrypt/live/sub.domain.xyz/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/sub.domain.xyz/privkey.pem; # managed by Certbot
  }
  </code></pre>
  <p>The idea is that <code>/chatterbox/api/connect/</code> is the endpoint to connect to the WebSocket server and this is where it is hosted with spark.</p>
  <p>I'm sorry if my nginx config is bad, it's an amalgamation of many StackOverflow threads :)</p>
  <p>Thanks</p>