Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将Rack::Deflater插入机架的位置?_Ruby On Rails_Ruby_Gzip_Rack - Fatal编程技术网

Ruby on rails 将Rack::Deflater插入机架的位置?

Ruby on rails 将Rack::Deflater插入机架的位置?,ruby-on-rails,ruby,gzip,rack,Ruby On Rails,Ruby,Gzip,Rack,我目前有以下情况: use Rack::Rewrite use Rack::Cache, {:verbose=>true, :metastore=>"memcached://localhost:11211/rack-cache/meta", :entitystore=>"memcached://localhost:11211/rack-cache/body"} use Rack::Rewrite use Rack::Lock use Rack::Deflater use Act

我目前有以下情况:

use Rack::Rewrite
use Rack::Cache, {:verbose=>true, :metastore=>"memcached://localhost:11211/rack-cache/meta", :entitystore=>"memcached://localhost:11211/rack-cache/body"}
use Rack::Rewrite
use Rack::Lock
use Rack::Deflater
use ActionController::Failsafe
use #<Class:0x007fb34be9ac90>
use ActionController::Session::DalliStore, #<Proc:0x007fb34bea3638@(eval):8 (lambda)>
use Rails::Rack::Metal
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActionController::StringCoercion
use Sass::Plugin::Rack
use Hassle
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new
使用机架::重写
使用Rack::Cache,{:verbose=>true,:metastore=>“memcached://localhost:11211/rack-缓存/元“,:entitystore=>”memcached://localhost:11211/rack-缓存/正文“}
使用Rack::重写
使用Rack::Lock
使用Rack::Deflater
使用ActionController::Failsafe
使用#
使用ActionController::Session::DalliStore#
使用Rails::Rack::Metal
使用ActionController::ParamSpaser
使用Rack::MethodOverride
使用Rack::Head
使用ActionController::StringImpression
使用Sass::Plugin::Rack
使用麻烦
使用ActiveRecord::ConnectionAdapters::ConnectionManagement
使用ActiveRecord::QueryCache
运行ActionController::Dispatcher.new
我可能错了,但把平减指数移到顶部难道没有意义吗?这样,任何和所有的交通都被压缩


感谢您的帮助。

最简单的插入方法是直接在config.ru中:

require ::File.expand_path('../config/environment',  __FILE__)
use Rack::Deflater
run My::Application
要确认它是否正常工作,请启动应用程序并使用curl点击:

curl -i --head "Accept-Encoding: gzip,deflate" http://localhost:5000
其中应返回标题:

Vary: Accept-Encoding
Content-Encoding: gzip

还有一个漂亮的gzip响应。

我不得不很早就插入它(在
ActionDispatch::Static
之前),如下所示:

# production.rb
config.middleware.insert_before ActionDispatch::Static, Rack::Deflater
您可以使用
rake中间件
进行确认(尽管这将查看您的开发设置)

rake中间件 使用Rack::Deflater 使用ActionDispatch::Static 使用Rack::Lock 使用# 使用Rack::Runtime 使用Rack::MethodOverride 使用ActionDispatch::RequestId 使用Rails::Rack::Logger 使用ActionDispatch::ShowExceptions 使用ActionDispatch::DebugExceptions 使用ActionDispatch::RemoteIp 使用ActionDispatch::Reloader 使用ActionDispatch::回调 使用ActionDispatch::Cookies 使用ActionDispatch::Session::CookieStore 使用ActionDispatch::Flash 使用ActionDispatch::ParamSpaser 使用Remotipart::中间件 使用ActionDispatch::Head 使用Rack::ConditionalGet 使用Rack::ETag 使用ActionDispatch::BestStandardsSupport 使用管理员::管理员 使用Rack::Mongoid::Middleware::IdentityMap 使用Rack::Pjax 运行MyApp::Application.routes
针对Maletor,有关如何从gzip中排除某些文件,请参阅:


尝试过它(在Sinatra中)并且效果很好。

使用选项“-I”(而不是“-I”)来设置仅返回curl的标题。上面的是大写字母I而不是小写字母L。这是个坏主意,因为它将GZip您的所有资产,包括您需要的图像文件。是更好的。@Maletor您的所有资产,包括图像文件,最好由前端服务器(如Nginx)提供服务,对吗?那么这就不是问题了。这个答案有有用的信息(+1),但实际上没有回答所问的问题(-1),这与config.ru中的位置以及该行是否应该靠近顶部有关。如果你把这句话加到一个很好的答案上,我很乐意投你一票。(我意识到这个问题最初可能是不同的,这可能直接以其原始形式回答了它。尽管如此,更新您的答案以匹配它将是有用的。)尽管如此,图像不应该是Gzip'ed。有没有跳过这些资产的平减指数的方法?这里只是一个提示:除非您有config.service\u static\u assets=true;),否则这不会起作用
> rake middleware
use Rack::Deflater
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f8e18455e90>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Remotipart::Middleware
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use Warden::Manager
use Rack::Mongoid::Middleware::IdentityMap
use Rack::Pjax
run MyApp::Application.routes