title: How to configure nginx to proxy ws (websocket) protocol
body: <p>I have successfully configurated Nginx as a reverse proxy for my web-application. It correctly redirects requests made from my Angular SPA to Web API written in Asp Core 2.1. However, in my Web API I want to use WebSockets that use 
  <code>ws://mydomain.com/ws</code> to establish a connection.</p>
  
  <p>This is how my sites-available looks now</p>
  
  <pre><code>server {
      listen 80;
      listen 443;
      ssl on;
      ssl_certificate /etc/***/***.crt;
      ssl_certificate_key /etc/***/***.key;
  
      root /home/***/***/***/wwwroot;
  
      # Add index.php to the list if you are using PHP
      index index.html;
  
      server_name my.domain.com;
      location / {
              try_files $uri $uri/ /index.html;
      }
      location /api/ {
              proxy_pass http://localhost:5000;
      }
      location /api/signalr {
  
              proxy_pass http://localhost:5000;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection $http_connection;
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;
      }
      location /ws{
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection $connection_upgrade;
              proxy_pass http://localhost:5000;
      }
  }
  </code></pre>
  
  <p>and the nginx.conf</p>
  
  <pre><code>http {
      map $http_upgrade $connection_upgrade{
              default upgrade;
              '' close;
      }
      upstream websocket{
              server my.domain.com;
      }
      #
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
      # server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # SSL Settings
      ##
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
      ssl_prefer_server_ciphers on;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
      gzip_disable "msie6";
  
      # gzip_vary on;
      # gzip_proxied any;
      # gzip_comp_level 6;
      # gzip_buffers 16 8k;
      # gzip_http_version 1.1;
      # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # Virtual Host Configs
      ##
  }
  </code></pre>
  
  <p>Any advice how can I debug my configuration to see why the requests are not redirected correctly?</p>