nginx服务器发送事件

时间:2013-08-19 05:36:49

标签: django nginx server-sent-events

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

我错过了什么?

1 个答案:

答案 0 :(得分:0)

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

http2_max_field_size 64k;
http2_max_header_size 512k;

并将其放入您的位置:

proxy_read_timeout 12小时;

这些为我解决了sse连接超时并重新连接的问题。

相关问题