title: Secure WSS via NGINX Proxy
body: <p>I`m using OpenNebula. 
  When I try to proxy traffic to a secure connection, there is a problem with the proxy of the websocket.</p>
  
  <p>I tried <a href="http://nginx.org/en/docs/http/websocket.html" rel="nofollow noreferrer">WebSocket proxying</a></p>
  
  <p><strong>nginx.conf</strong></p>
  
  <pre><code>map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
  }     
  </code></pre>
  
  <p><strong>default_server.conf</strong></p>
  
  <pre><code>upstream sunstone {
      server 127.0.0.1:9869;
  }
  
  upstream websocketproxy {
      server 127.0.0.1:29876;
  }
  
  server {
      listen *:80;
      server_name example.com;
      rewrite ^(.*)$ https://example.com$1 permanent;
  }
  
  server {
      listen 443 ssl http2 deferred;
      ssl on;
      ssl_session_timeout 24h;
      ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  
      access_log  /var/log/nginx/opennebula-sunstone-access.log;
      error_log  /var/log/nginx/opennebula-sunstone-error.log;
  
      client_max_body_size 1G;
  
      location / {
          proxy_pass http://sunstone;
          proxy_redirect     off;
          log_not_found      off;
          proxy_set_header   X-Real-IP $remote_addr;
          proxy_set_header   Host $http_host;
          proxy_set_header   X-Forwarded-FOR $proxy_add_x_forwarded_for;
      }
  
      location /websockify {
          proxy_pass http://websocketproxy;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
      }
  }
  </code></pre>
  
  <p>When I try to open VNC console - get those errors.</p>
  
  <pre><code>Msg: noVNC ready: native WebSockets, canvas rendering
  VM1479:37 WebSocket connection to 'wss://example.com:29876/?token=azy36gz3k4ibsuxsphwg' failed: Error in connection establishment: net::ERR_CONNECTION_RESET
  WebSocket on-error event
  WebSocket on-close event
  Msg: Server disconnected (code: 1006)
  </code></pre>
  
  <p>In OpenNebula <code>sunstone-server.conf</code> set the next:</p>
  
  <pre><code>:vnc_proxy_port: 29876
  :vnc_proxy_support_wss: yes
  :vnc_proxy_cert: /etc/letsencrypt/live/example.com/fullchain.pem;
  :vnc_proxy_key: /etc/letsencrypt/live/example.com/privkey.pem
  :vnc_proxy_ipv6: false
  :vnc_request_password: false
  </code></pre>
  
  <p>How I can forward encrypt wss?</p>