【发布时间】:2012-04-21 02:12:00
【问题描述】:
我正在尝试在我的应用程序中使用 HTTP_IF_MODIFIED_SINCE 标头来确定资源是否过时/新鲜,并在这些情况下呈现 200/304。 在我的开发环境中,一切正常,但我一辈子都无法让它在生产环境中工作。
我正在使用乘客 3.0.11 和 Nginx 1.0.13。
如下所示,我尝试了proxy_pass_header、proxy_set_header、passenger_pass_header 和passenger_set_cgi_param。最后一个实际上设置了一个 HTTP_IF_MODIFIED_SINCE 标头,但它是空的... 任何帮助/想法将不胜感激!
我的配置:
server {
listen 80 default_server;
root /home/rails/myapp/current/public;
passenger_enabled on;
charset utf-8;
proxy_pass_header If-Modified-Since;
proxy_set_header If-Modified-Since $http_if_modified_since;
passenger_pass_header If-Modified-Since;
passenger_set_cgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
location ~ \.(aspx|jsp|cgi)$ {
return 410;
}
location ~ ^/(assets)/ {
# http://guides.rubyonrails.org/asset_pipeline.html#server-configuration
# gzip_static on;
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
}
【问题讨论】:
-
你需要那些指令来操纵标题吗?我从来不需要那样的东西
-
嗯,不。无论有没有这些指令,我都没有在我的应用程序中看到 HTTP_IF_MODIFIED_SINCE 标头。 (
passenger_set_cgi_param创建了 header 属性,但它是空的)。也许它在那之前在 Nginx 的某个地方被过滤了?你能发布你的 Nginx conf 吗?
标签: ruby-on-rails nginx http-headers passenger