我正在尝试准备将我们的环境迁移到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。
<script>
jQuery(document).ready(function(){
var source = new EventSource("/feed");
source.addEventListener('update', function(e){
console.log(e.data);
});
});
</script>
这是控制器:
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中的服务器,注意/ 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起作用了:
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(用于压缩对浏览器的响应)将干扰非缓冲响应,例如文本/事件流。
查看我的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页面。
现在一切正常!以及我最初尝试使用的仪表板工具。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句