unit
unit copied to clipboard
Are Python WebSockets under SSL intended to work?
Hi, I recently changed over our infrastructure to use Nginx Unit, and mostly it is going great. The only thing that is not going great is that this seems to have broken WebSockets for our app in production.
Our app is a Python ASGI app (FastAPI) so from what I've read it seems like WebSockets should be supported just fine, and while developing locally using Unit they do indeed work great. However in production they seem to be broken. As far as I can figure, the only difference between dev and prod is that prod is (of course) using an SSL cert, while dev on localhost is of course not. The stack before was Gunicorn w/ Uvicorn + Nginx + HAProxy, which had to have a number of tweaks and fiddles at the different layers to get WS working correctly, but working they were.
Is this a known issue? Are there any remediations I can try? A great thing about Unit is that it has massively reduced the config required to serve our application. The bad thing is that when something is broken it is hard to try to debug different layers of the stack because there is only the one 😅. I've tried debugging at the application level itself and that seems to be a deadend, so for now I've concluded the issue must be with how Unit is working alongside the application/WebSockets.
For reference, here are my Unit configs in dev and prod.
dev config
{
"listeners": {
"*:5000": {
"pass": "applications/supernotes"
}
},
"applications": {
"supernotes": {
"type": "python 3.11",
"processes": 8,
"path": "/Users/connor/supernotes/backend/",
"working_directory": "/Users/connor/supernotes/backend/",
"home": "/Users/connor/Library/Caches/pypoetry/virtualenvs/supernotes-0y77xQ4Y-py3.11",
"module": "api.main",
"callable": "app"
}
}
}
prod config
{
"listeners": {
"*:80": {
"pass": "routes/acme"
},
"*:443": {
"pass": "applications/supernotes",
"tls": {
"certificate": "certbot"
}
}
},
"routes": {
"acme": [{
"action": {
"share": "/var/www/certs/$uri"
}
}]
},
"applications": {
"supernotes": {
"type": "python 3.11",
"processes": 8,
"path": "/var/www/sn-prod-deploy/backend",
"working_directory": "/var/www/sn-prod-deploy/backend",
"home": "/var/www/sn-prod-deploy/venv",
"module": "api.main",
"callable": "app"
}
}
}
Thanks for any help and thank you for making a great piece of software like Unit!