【问题标题】:Mongrel::DirHandler equivalent for PassengerMongrel::DirHandler 等效于乘客
【发布时间】:2010-09-18 20:02:11
【问题描述】:

我正在使用 Mongrel::DirHandler 来控制静态文件的响应头 - 这在我的开发机器上非常有用。我的生产机器使用Passenger,所以我的标题没有设置。使用Passenger时如何控制静态文件的标头?

sn-p 来自我的 environment.rb:

if defined? Mongrel::DirHandler
  module Mongrel
    class DirHandler
      def send_file_with_expires(req_path, request, response, header_only=false)

        if req_path =~ /((\/images)|javascripts|stylesheets)/
          response.header['Cache-Control'] = 'max-age=315360000'
          response.header['Expires'] = (Time.now + 10.years).rfc2822
        else
          response.header["Last-Modified"] = Time.now.httpdate
          response.header["Expires"] = 0
          # HTTP 1.0
          response.header["Pragma"] = 'no-cache'
          # HTTP 1.1 ‘pre-check=0, post-check=0′ (IE specific)
          response.header["Cache-Control"] = 'no-store, no-cache, must-revalidate, max-age=0, pre-check=0, post-check=0'
        end

        send_file_without_expires(req_path, request, response, header_only)
      end
      alias_method :send_file_without_expires, :send_file
      alias_method :send_file, :send_file_with_expires
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby apache passenger mongrel


    【解决方案1】:

    由于您使用的是Passenger,我假设您使用的是apache,因此您的请求不再通过Mongrel。如果是这样,您可以在应用程序的public 目录内的.htaccess 文件上建立规则。

    Here's an explination on how to do it.

    【讨论】:

      猜你喜欢
      • 2015-04-12
      • 2011-04-01
      • 2011-01-01
      • 2015-09-11
      • 1970-01-01
      • 2019-11-06
      • 2011-11-03
      • 2015-11-12
      • 1970-01-01
      相关资源
      最近更新 更多