title: How to setup secure websockets with nginx
body: <p>I have a webserver running on port 9000 I want to make it available on port 80, and also I want to make a websocket connection available on port 9021. If i run this over <code>http</code> everything works fine. But when I go to <code>https</code> the websocket cannot be connected.</p>
  
  <p>Here's my nginx config: this gives the warning:</p>
  
  <p><code>nginx: [warn] conflicting server name "oyun.net" on 0.0.0.0:443, ignored</code></p>
  
  <pre><code>server {
       listen 443 ssl;
       server_name          oyun.net;
       ssl_certificate      /etc/key.pem
       ssl_certificate_key  /etc/key2.pem
       listen 80;
       location / {
           proxy_pass http://localhost:9000
       }
  }
  
  server {
       listen 443 ssl;
       server_name          oyun.net;
       ssl_certificate      /etc/key.pem
       ssl_certificate_key  /etc/key2.pem
       listen 9021;
       location / {
          proxy_pass http://localhost:9000;
          proxy_http_version 1.1;
          proxy_set_header upgrade $http_upgrade;
          proxy_set_header connection "upgrade";
          proxy_set_header x-real-ip $remote_addr;
          proxy_set_header host $host;
          proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
       }
   }
  </code></pre>
  
  <p>Here's the browser error:</p>
  
  <pre><code>WebSocket connection to 'wss://oyun.net:9021/socket/v1?sri=tcylqwzjnl' failed: 
  
  Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
  </code></pre>