【发布时间】:2013-08-20 20:19:25
【问题描述】:
我尝试让 django-sse 在我的 aws 实例上工作。为了开发,我的 django 在 localhost:8000 上运行,EventSource 指向类似 localhost:8000/stream1/?lastEventId=&r=5546342101865558 的东西。我会立即收到事件。
按照这篇帖子EventSource / Server-Sent Events through Nginx 我在生产中尝试了这个配置:
upstream message_upstream {
server 54.216.184.203:443;
}
server {
listen 80;
server_name ${cfg:domain_list} ${cfg:redirect_domain_list};
rewrite ^ https://${cfg:domain}$request_uri? permanent;
}
server {
listen 443 ssl;
server_name ${cfg:domain_list};
access_log /var/log/nginx/${cfg:domain_slug}.access.log;
root ${buildout:directory}/public_html;
ssl on;
ssl_certificate /etc/ssl/certs/.... ;
ssl_certificate_key /etc/ssl/certs/......;
location / {
include uwsgi_params;
uwsgi_pass unix:///tmp/${cfg:domain_slug}.sock;
}
location /media {
}
location /static {
}
location ~ ^/stream1 {
proxy_pass https://message_upstream;
proxy_buffering off;
proxy_cache off;
proxy_set_header Host $host;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
}
}
使用 SSL,我的配置与 stackoverflow 帖子中提到的配置不同。我的亚马逊控制台中的监视器显示了大量的流量。在 nginx 日志中我得到:
2013/08/16 06:00:18 [error] 25173#0: *6473 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 54.216.184.203, server: nachhilfe.impac.ch, request: "GET /stream1/?lastEventId=&r=4599838461726904 HTTP/1.1", upstream: "https://54.216.184.203:443/stream1/?lastEventId=&r=4599838461726904", host: "nachhilfe.impac.ch", referrer: "https://nachhilfe.impac.ch/user/1/"
站点的其余部分运行正常,正如我的机器上提到的,sse 部分正在运行。
我错过了什么?
【问题讨论】:
-
SSE位置是无限工作,还是在一定时间后停止并重新连接?
-
如果没有为 EventSource 获取事件,萤火虫会在大约 40 秒后显示中止。否则我的 nginx 日志中每秒大约有 20 个错误。
-
所以它似乎一直在尝试重新连接。
-
当我收到“[error] 31812#0: *182 upstream timed out (110: Connection timed out) while reading response header from upstream”时每秒 20-30 次,萤火虫显示中止请求,但大约 40 秒内只有一个请求。
-
尝试在nginx中添加这些规则
client_body_timeout 1m; client_header_timeout 1m;
标签: django nginx server-sent-events