我使用Amazon Elastic Beanstalk(Nginx 1.4.2 + Passenger 4.0.20 + Ruby 1.9.3)部署使用Server Sent Events的Sinatra應用程序。一切工作完美的本地機器使用瘦。但是,在AWS Elastic Beanstalk上,連接會在毫秒後丟棄。服務器在Elastic Beanstalk上使用Sinatra發送事件/ EventSource
服務器代碼如下所示:
get '/stream', provides: 'text/event-stream' do
response.headers['X-Accel-Buffering'] = 'no'
stream :keep_open do |out|
settings.connections << out
out.callback { settings.connections.delete(out) }
end
end
在服務器日誌中我看到了連接超時:服務器塊下
2013/11/20 19:45:46 [info] 9716#0: *35 client closed connection while waiting for request, client: xxx.xxx.xxx.xxx, server: 0.0.0.0:80
試過nginx的配置這裏建議(EventSource/Server-Sent Events through Nginx)和儘管標題響應改變了,但它還沒有工作。
(我不得不設置Nginx的文件X-ACCELL-緩衝爲好,因爲它不會採取與西納特拉服務器代碼設置的設置)
響應頭看起來是這樣的:
HTTP/1.1 200 OK
Content-Type: text/event-stream;charset=utf-8
Date: Wed, 20 Nov 2013 20:03:06 GMT
Server: nginx/1.4.2 + Phusion Passenger 4.0.20
Status: 200 OK
X-Accel-Buffering: no
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 4.0.20
transfer-encoding: chunked
Connection: keep-alive
任何想法?
在此先感謝。
我試過了,它沒有工作。我通過使用常規EC2實例最終放棄了Elastic Beanstalk和ngnix。 – buzali