Proxy Websockets and HTTP through the same location in Nginx

The easiest way I found was to jump to different locations based on the "Upgrade" header:

server {
  # ...

  location / {
    try_files /nonexistent @$http_upgrade;
  }

  location @websocket {
    # websocket related stuff
  }

  location @ {
    # web related stuff
  }
}