我正在尝试使用Gunicorn,Nginx,Postgres和Supervisor在生产环境中部署Django通道。尽管我已经能够正确处理http请求,但是我无法配置websocket配置
这是nginx配置
upstream app_server {server unix:/home/datasleek/tracker/run/gunicorn.sock fail_timeout=0;}
upstream websocket {server ip-address:80;}
server
{
listen 80;
server_name ip-address;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ { alias /home/datasleek/tracker/staticfiles/; }
location /media/ { alias /home/datasleek/tracker/media/; }
client_max_body_size 4G;
access_log /home/datasleek/tracker/logs/nginx-access.log;
error_log /home/datasleek/tracker/logs/nginx-error.log;
location /ws/ {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
proxy_pass http://app_server;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
这是主管配置
[program:tracker]
command=/home/datasleek/trackervenv/bin/gunicorn_start
user=datasleek
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/datasleek/tracker/logs/gunicorn.log
[program:serverinterface]
directory=/home/datasleek/tracker/
command= /home/datasleek/trackervenv/bin/daphne -b 0.0.0.0 -p 80 tracker.asgi:channel_layer
autostart=true
autorestart=true
stopasgroup=true
user=datasleek
stdout_logfile = /home/datasleek/tracker/logs/daphne.log
redirect_stderr=true
#[program:tracker_asgi_daphne]
#directory=/home/datasleek/tracker/
#command=/home/datasleek/trackervenv/bin/daphne -u /home/datasleek/tracker/daphne.sock --root-path= home/datasleek/tracker tracker.asgi:channel_layer
#stdout_logfile = /home/datasleek/tracker/logs/daphne.log
[program:tracker_asgi_workers]
command=/home/datasleek/trackervenv/bin/python /home/datasleek/tracker/manage.py runworker
stdout_logfile = home/datasleek/tracker/logs/worker.log
process_name=asgi_worker%(process_num)s
numprocs=3
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8 ; Set UTF-8 as default encoding
autostart=true
autorestart=true
redirect_stderr=True
stopasgroup=true
这些是我尝试连接的一些websocket路径
ws://ip-address/agent-presence/
ws://ip-address/stream/
我收到以下错误;
websocketbridge.js:118与'ws:// ip-address / agent-presence /'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:404
P.S:我知道有关此错误的问题已多次提出,但我真的无奈地摆脱了这个问题。自上周以来,我一直在尝试,但是尽管应用了与Google和youtube不同的方法,却无法解决此问题。