为什么 Django 频道在服务器上不起作用?

时间:2021-05-01 20:05:13

标签: django nginx websocket django-channels daphne

我使用 django-channel 创建了一个 django websocket 聊天应用程序,它在 localhost 中运行良好,但是当我在服务器上使用 daphne 运行它时,nginx 无法正常工作。因为我在 journalctl -u daphne 和 journalctl -u nginx 我想我的 nginx 配置有问题 这是sites-available中的nginx配置,也在sites-enabled中链接:

服务器{

listen 80;
server_name {DOMAIN-OR-IP};

location /ws/ {
    proxy_pass http://0.0.0.0:9000;
    proxy_http_version 1.1;

    proxy_read_timeout 86400;
    proxy_redirect     off;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
}

location = /favicon.ico { access_log off; log_not_found off; }

location /static_in_env/ { 
    root /home/mhfd/newblog17/blog23;
    
    }

location / {
    include proxy_params;
    proxy_pass http://unix:/home/mhfd/newblog17/blog23/blog23.sock;
    
    }  

}

这是 systemd 中 daphne.service 的配置:

[Unit]
Description=daphne daemon
After=network.target

[Service]
User={USER}
Group=www-data
WorkingDirectory={PROJECT-DIRECTORY}
ExecStart={VIRTUAL-ENVIRONMENT-ADDRESS}/bin/daphne --bind 0.0.0.0 --port 9000 --verbosity 0 {PROJECT-NAME}.asgi:application

[Install]
WantedBy=multi-user.target

我在日志中没有发现错误,但 websocket 聊天(发送和接收)不起作用?

error image

0 个答案:

没有答案
相关问题