我正在使用 Mongrel::DirHandler 来控制静态文件的响应标头 - 这在我的开发机器上效果很好。我的生产机器使用 Passenger,因此我的标头未设置。使用 Passenger 时如何控制静态文件的标头?
我的环境中的片段.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
由于您使用的是 Passenger,我假设您在 apache 下,因此您的请求不再通过 Mongrel。如果是这样,您可以制定规则.htaccess
文件内的public
您的应用程序的目录。
这是有关如何执行此操作的说明。 http://forum.powweb.com/showthread.php?t=70536
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)