2

我尝试让 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 部分正在运行。

我错过了什么?

4

1 回答 1

0

尝试将其添加到您的服务器中:

http2_max_field_size 64k;
http2_max_header_size 512k;

并将其放入您的位置:

proxy_read_timeout 12h;

这些为我解决了 sse 连接超时和重新连接。

于 2020-12-08T21:00:35.703 回答