Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Nginx + websockets #948

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ You should ensure that the `X-Forwarded-For` and `X-Forwarded-Proto` headers are

Here's how a simple Nginx configuration might look. This example includes setting proxy headers, and using a UNIX domain socket to communicate with the application server.

It also includes some basic configuration to forward websocket connections. For more info on this, check [Nginx recommendations][nginx_websocket].

```conf
http {
server {
Expand All @@ -259,6 +261,8 @@ http {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://uvicorn;
Expand All @@ -269,6 +273,11 @@ http {
root /path/to/app/static;
}
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

upstream uvicorn {
server unix:/tmp/uvicorn.sock;
Expand Down Expand Up @@ -309,5 +318,6 @@ It also possible to use certificates with uvicorn's worker for gunicorn
$ gunicorn --keyfile=./key.pem --certfile=./cert.pem -k uvicorn.workers.UvicornWorker example:app
```

[nginx_websocket]: https://nginx.org/en/docs/http/websocket.html
[letsencrypt]: https://letsencrypt.org/
[mkcert]: https://github.com/FiloSottile/mkcert