title: PHP websockets with nginx via SSL
body: <p>How to setup websockets with PHP in nginx?</p>
  
  <p>I have looked at this tutorial, but cant make it work</p>
  
  <p><a href="https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket">https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket</a></p>
  
  <p>Have copied the three files into the root of the www directory</p>
  
  <p><code>/index.php</code>
  <code>/jquery-3.1.1.js</code>
  <code>/websocket/server.php</code></p>
  
  <p>In <code>index.php</code> I have changed the URI</p>
  
  <pre><code>var wsUri = "wss://domain.com/websocket/server.php";
  </code></pre>
  
  <p>In nginx I have added this</p>
  
  <pre><code>http {
      map $http_upgrade $connection_upgrade {
          default upgrade;
          ''      close;
      }
      server {
          location /websocket/ {
              proxy_pass https://domain.com:9000/websocket/server.php;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection $connection_upgrade;
          }
      }
  }
  </code></pre>
  
  <p><a href="http://nginx.org/en/docs/http/websocket.html">http://nginx.org/en/docs/http/websocket.html</a></p>
  
  <p>To start websocket server</p>
  
  <pre><code>php -q /var/www/websocket/server.php
  </code></pre>
  
  <p>The chat is located at <code>https://domain.com/chat.php</code> and loads but get this error in the chat window <code>Error Occurred - Connection closed</code></p>
  
  <p>Have also tried to connect through this tool, but get this error</p>
  
  <p><a href="http://www.websocket.org/echo.html">http://www.websocket.org/echo.html</a></p>
  
  <pre><code>ERROR: undefined
  DISCONNECTED
  </code></pre>
  
  <p>If requested through browser</p>
  
  <pre><code>wss://domain.com/websocket/server.php
  
  
  ERR_DISALLOWED_URL_SCHEME
  </code></pre>