title: Error during WebSocket handshake: Unexpected response code: 301
body: <p>I have already looked into the answer to <a href="https://stackoverflow.com/questions/35041614/ror-5-0-0-actioncable-wss-websocket-handshake-unexpected-response-code-301">RoR 5.0.0 ActionCable wss WebSocket handshake: Unexpected response code: 301</a> but it was not applicable to my case. </p>
  
  <p>I use an nginx-proxy as a front for several web-servers running in docker-containers. I use the nginx-config-template from <a href="https://github.com/jwilder/nginx-proxy" rel="noreferrer">https://github.com/jwilder/nginx-proxy</a></p>
  
  <p>Now in my docker-container I have another nginx with the following config:</p>
  
  <pre><code>map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
  }
  
  upstream websocket {
      server my-websocket-docker-container:8080;
  }
  
  server {
      root /src/html;
  
  
      location /websocket/ {
          resolver 127.0.0.11 ipv6=off;
          proxy_pass http://websocket;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
      }
  
      location / {
          # try to serve file directly, fallback to index.php
          try_files $uri /index.php$is_args$args;
      }
  
      ...
  
  }
  </code></pre>
  
  <p>When trying to connect to <strong>wss://example.com/websocket</strong> I get the aforementioned error about unexpected response code 301. When I curl the websocket-url manually I can see the nginx response telling me "301 moved permanantly". But why? Where is this coming from?</p>
  
  <p>Can anybody help? Thanks!</p>