2

I try to get django-sse working on my aws instance. For development my django runs on localhost:8000 and the EventSource points to something like this localhost:8000/stream1/?lastEventId=&r=5546342101865558. I receive the events immediately.

Following this post EventSource / Server-Sent Events through Nginx I tried this config in production:

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;
}
}

With SSL my configuration differs from the one mentioned in the stackoverflow post. The monitors in my amazon console show a huge amount of traffic. And in the nginx log I get:

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/"

The rest of the site is running correctly and as mentioned on my machine the sse part is working.

What am I missing?

Community
  • 1
  • 1
  • Does the SSE location work infinitely, or does it stop after a certain time and reconnect again ? – Mohammad AbuShady Aug 19 '13 at 10:47
  • If there is no event to get for EventSource firebug shows an aborted after about 40 seconds. Otherwise I have about 20 errors per second in my nginx log. – user2695200 Aug 19 '13 at 13:17
  • So it seems that it tries to reconnect the whole time. – user2695200 Aug 19 '13 at 13:23
  • And while I receive "[error] 31812#0: *182 upstream timed out (110: Connection timed out) while reading response header from upstream" 20-30 times in a second, firebug shows aborted for the request, but there is only one request in about 40 seconds. – user2695200 Aug 19 '13 at 14:15
  • try adding these rules in nginx `client_body_timeout 1m; client_header_timeout 1m;` – Mohammad AbuShady Aug 20 '13 at 07:35
  • I've added these two lines in the server section outside of location but there is no difference. The error_log still shows about 20 upstream timed out per second. – user2695200 Aug 20 '13 at 08:43
  • did you try to manually open the SSE URL ? – Mohammad AbuShady Aug 20 '13 at 09:31
  • I added text/event-stream to the mime.types in the nginx settings. That was most likely missing too. I have to test it again... – user2695200 Aug 20 '13 at 11:40
  • I always get a 504 Gateway Time-Out...also when opening the sse url manually. Locally my django runs on port 8000 and the sse's are accessed through port 8000 too. Do I need to have a proxy? Or should the sse's available through port 443 in production? – user2695200 Sep 06 '13 at 15:29

1 Answers1

0

try add this into your server:

http2_max_field_size 64k;
http2_max_header_size 512k;

and this into your location:

proxy_read_timeout 12h;

These solved sse connection time-out and reconnecting for me.

micky
  • 31
  • 3