I successfully deployed uwsgi + nginx + Django. But I want to communicate with my server using websocket.
I followed this tutorial to handle normal https requests. https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
The nginx conf file settings are like this:
upstream django {
server unix:///path/to/your/mysite/mysite.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 443 ssl; # managed by Certbot
# the domain name it will serve for
server_name example.com; # substitute your machine's IP address or FQDN
charset utf-8;
location /static {
alias /path/to/your/mysite/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}
I Googled a lot and found that people recommended to add these settings:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
It does not work. I did not use proxy_pass
because I am already using uwsgi_pass django;
and my client attempts to connect using websocket to the same url (location) I uwsgi_pass to django. I looked into uwsgi docs and found this page:
https://uwsgi-docs.readthedocs.io/en/latest/WebSockets.html
According to this page, I do not need additional settings if I just add --http-websockets option. So I did. Like this:
/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --http-websockets www-data --daemonize /var/log/uwsgi-emperor.log
It is added in /etc/rc.local. This command does not work either. I also tried to add http-websockets = true
to .ini file. It even made uwsgi stop. So I removed that option.
What is wrong here?
I get 400 Bad Request for every websocket request. The only data I see is (Opcode -1). There is no graphql error message.