title: Nginx websockets + SSL not working (net::ERR_CERT_COMMON_NAME_INVALID)
body: <p>I have a problem with running a websocket server on Nginx. This is my Nginx default.conf:</p>
  
  <pre><code>upstream websocket {
      server xx.xx.xx.xx:8080;
  }
  
  server {
      listen 80;
      listen [::]:80;
      server_name domain.com *.domain.com;
      return 301 https://$server_name$request_uri;
  }
  
  server {
      listen 443 ssl default_server;
      listen [::]:443 ssl default_server;
      ssl on;
      ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
      ssl_session_cache shared:SSL:10m;
      ssl_session_timeout 5m;
  
      root /var/www/html;
  
      index index.php index.html index.htm index.nginx-debian.html;
  
      server_name domain.com *.domain.com;
  
      location / {
          try_files $uri $uri/ =404;
      }
  
      location ~ \.php$ {
          include snippets/fastcgi-php.conf;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      }
  
      location ~ /\.ht {
          deny all;
      }
  
      location /ws {
              proxy_pass http://websocket;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "upgrade";
              proxy_set_header Host $host;
      }
  
  }
  </code></pre>
  
  <p>I get the following error in <strong>chrome</strong>:</p>
  
  <blockquote>
    <p>(index):2 WebSocket connection to 'wss://xx.xx.xx.xx/ws:8080' failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID</p>
  </blockquote>
  
  <p>I think it has something to do with certificates (SSL) but I really have no idea to fix this!</p>
  
  <p>Thanks in advance!</p>
  
  <p>Edit:</p>
  
  <p>My index.php file is</p>
  
  <pre><code>&lt;script&gt;
      var conn = new WebSocket('wss://xx.xx.xx.xx/ws');
      conn.onopen = function(e) {
      console.log("Connection established!");
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>When I change xx.xx.xx.xx to domain.com I get a handshake error code 504.</p>
  
  <p>Btw I'm running a websocket server via php (php server.php) with ratchet following this example: <a href="http://socketo.me/docs/hello-world" rel="nofollow noreferrer">http://socketo.me/docs/hello-world</a></p>