我低于错误
WebSocket连接到' ws:// localhost / ws / testNoti?subscribe-broadcast& publish-broadcast& echo'失败:WebSocket握手期间出错:意外响应代码:500
Websocket连接中断了!
主管conf文件
[unix_http_server]
username = ubuntu
password = password
[program:uwsgi]
command=/home/ubuntu/bxd-life/venv/bin/uwsgi --ini /home/ubuntu/bxd-life/bxd/bxd.ini
autostart=true
user=ubuntu
autorestart=true
stderr_logfile = /home/ubuntu/bxd-life/logs/err.log
stdout_logfile = /home/ubuntu/bxd-life/logs/out.log
stopsignal=INT
[program:uwsgi_ws]
command = /home/ubuntu/bxd-life/venv/bin/uwsgi --http :8080 --gevent 1000 --http-websockets --workers=2 --master --module bxd.wsgi_websockets
#directory=/home/ubuntu/bxd-life/bxd
autostart=true
autorestart=true
starttries=5
user=ubuntu
environment=DJANGO_SETTINGS_MODULE='bxd.settings'
nginx conf文件
upstream app_server {
server localhost:8000;
}
upstream web_socket_server {
server localhost:8080 fail_timeout=0;
}
server {
listen 80;
server_name _;
location /static/ {
alias /home/ubuntu/bxd-life/bxd/static/;
expires 30d;
}
location /ws/ {
proxy_pass http://web_socket_server;
proxy_http_version 1.1;
#proxy_redirect ws://$server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
}
wsgi_websockets.py
import os
import gevent.socket
import redis.connection
redis.connection.socket = gevent.socket
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bxd.settings")
from ws4redis.uwsgi_runserver import uWSGIWebsocketServer
application = uWSGIWebsocketServer()
上述内容适用于./manage.py runserver
但不适用于nginx!
非常感谢任何帮助。