3

私は Mongrel::DirHandler を使用して静的ファイルの応答ヘッダーを制御しています - これは私の開発マシンでうまく機能します。私の運用マシンは Passenger を使用しているため、ヘッダーが設定されていません。Passenger の使用時に静的ファイルのヘッダーを制御するにはどうすればよいですか?

私の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
4

1 に答える 1

2

あなたはPassengerを使用しているので、私はあなたがapacheの下にいると思います、それであなたの要求はもうMongrelを通過していません。その場合は、アプリケーション.htaccessのディレクトリ内のファイルにルールを設定できpublicます。

これがその方法の説明です。

于 2008-10-23T17:11:04.993 に答える