我们有一个使用频道包的应用程序,并且工作得很好......在本地主机上。一旦我们点击 staging 并nginx
在 Django 前面放置一个框(使用 SSL),我们就可以连接到套接字,但客户端没有收到任何消息。
Nginx 配置:
worker_processes auto;
error_log /dev/stdout info;
user nobody nogroup;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
upstream ws_server {
server unix:/tmp/daphne.sock fail_timeout=0;
}
server {
# redirect all http requests to https
listen 80;
listen [::]:80 ipv6only=on;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
client_max_body_size 4G;
server_name changemyip.com;
keepalive_timeout 5;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets on;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
location /ws/ {
try_files $uri @proxy_to_ws;
}
location @proxy_to_ws {
proxy_pass http://ws_server;
proxy_redirect off;
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-Proto $scheme;
# Websocket specific
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_connect_timeout 86400;
proxy_read_timeout 86400;
proxy_send_timeout 86400;
}
...
ssl_protocols TLSv1.1 TLSv1.2;
...
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
}
}
Django 使用 gunicorn 运行,对于 websockets,我升级了一个 daphne 服务器。我可以在 daphne 日志中看到我的客户端正在连接,但仍然没有收到从 daphne 到客户端的消息。
Daphne 正在创建一个 nginx 用来通信的 unix 套接字:
daphne main.asgi:channel_layer -u /tmp/daphne.sock