我正在尝试将我们的环境转移到Rails 4并解决所有问题.遗憾的是,我们目前使用的是Centos 5.5,因此只需要一些障碍就可以让Rails启动并运行.这包括安装python 2.6和node.js以使extjs正常工作.
而现在我被卡住了.使用全新的rails 4.0.2应用程序,我有简单的ActionController :: Live示例在Puma的开发中正常运行.但在Apache + Passenger的生产中,它根本不会将数据发送回浏览器(Firefox)
production.rb有
config.allow_concurrency = true
这是index.html中的HTML/JS.
这是控制器:
class LiveController < ApplicationController include ActionController::Live respond_to :html def feed response.headers['Content-Type'] = 'text/event-stream' response.headers['X-Accel-Buffering'] = 'no' while true do response.stream.write "id: 0\n" response.stream.write "event: update\n" data = {time: Time.now.to_s}.to_json response.stream.write "data: #{data}\n\n" sleep 2 end end end
我可以看到请求在Firebug中发送到服务器通知spinner on/feed:
Apache/Passenger Config有这个:
LoadModule passenger_module /usr/local/ordernow/lib/ruby/gems/2.0.0/gems/passenger-4.0.27/buildout/apache2/mod_passenger.so PassengerRoot /usr/local/ordernow/lib/ruby/gems/2.0.0/gems/passenger-4.0.27 PassengerDefaultRuby /usr/local/ordernow/bin/ruby RailsAppSpawnerIdleTime 0 PassengerMinInstances 1
Apache日志没有显示任何内容.就像它永远不会连接到服务器.另一个奇怪的事情是命令行的卷曲起作用:
curl -k -i -H "Accept: text/event-stream" https://10.47.47.44:8446/feed HTTP/1.1 200 OK Date: Thu, 27 Mar 2014 16:52:52 GMT Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/1.0.0e Phusion_Passenger/4.0.27 X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-UA-Compatible: chrome=1 X-Accel-Buffering: no Cache-Control: no-cache X-Request-Id: 46fca6bb-4c6a-49f4-b0d6-2cbc5f0a63a5 X-Runtime: 0.002065 X-Powered-By: Phusion Passenger 4.0.27 Set-Cookie: request_method=GET; path=/ Status: 200 OK Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: text/event-stream id: 0 event: update data: {"time":"2014-03-27 10:52:52 -0600"} id: 0 event: update data: {"time":"2014-03-27 10:52:54 -0600"}
我认为它必须是Apache的东西,但我不确定.
好吧,我终于通过一堆谷歌搜索来解决这个问题,这使我看到mod_deflate(用于压缩对浏览器的响应)将干扰非缓冲响应,如text/event-stream.
看着我的httpd.conf,我发现了这个:
SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI \.(?:gif|jpg|png|ico|zip|gz)$ no-gzip # Restrict compression to these MIME types AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/css # Level of compression (Highest 9 - Lowest 1) DeflateCompressionLevel 9
SetOutputFilter DEFLATE 打开所有响应的压缩,使其余的AddOutputFilterByType指令不再需要.这显然是httpd.conf中的一个错误.我删除了这一行,并验证压缩仍然适用于html页面.
现在一切都很棒!以及我试图在第一时间开始使用的仪表板工具.