server {
  # ...

  location / {
    # If "Websocket" is in Upgrade header, then @websocket will take effect,
    # otherwise @ will take effect.
    try_files /nonexistent @$http_upgrade;
  }

  location @websocket {
    # websocket related stuff
  }

  location @ {
    # web related stuff
  }
}