title: nginx failed to open websocket connection due to invalid connection header: keep alive
body: <p>i have a python websocket server and i want to served it in nginx. so this is my server code :</p>
  
  <pre><code>import asyncio 
  import websockets
  
  
  async def recv_message(websocket, path):
  
      message = await websocket.recv()
      print(message)
  
  
  def main():
  
      start_server = websockets.serve(recv_message, "localhost", 8765)
  
      asyncio.get_event_loop().run_until_complete(start_server)
      asyncio.get_event_loop().run_forever()
  
  if __name__ == "__main__":
  
      main()
  </code></pre>
  
  <p>and this is my nginx config:</p>
  
  <pre><code>server{
       listen 8765;
       server_name localhost;
  
       location / {
       proxy_pass ws://localhost;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
  
   }
  
  }
  
  </code></pre>
  
  <p>when i go to <code>localhost:8765</code>, i get a message from the webpage, it says</p>
  
  <pre><code>Failed to open a WebSocket connection: invalid Connection header: keep-alive.
  
  You cannot access a WebSocket server directly with a browser. You need a WebSocket client.
  </code></pre>
  
  <p>how do i open the websocket connection? is there any mistake in my configuration? i'm keep stucking in this problem since i'm new in software engineering. thanks in advance</p>