【问题标题】:HTTP_IF_MODIFIED_SINCE header not passed to Rails app (Nginx, Passenger)HTTP_IF_MODIFIED_SINCE 标头未传递给 Rails 应用程序(Nginx,Passenger)
【发布时间】: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


【解决方案1】:

要使其与包含下划线的非标准标头一起使用,请在 nginx.conf 文件中的 http 或 server 块中执行此操作:

underscores_in_headers on;
ignore_invalid_headers off;

在服务器块中:

proxy_pass_header HTTP_IF_MODIFIED_SINCE

如果您有需要处理的旧 HTTP 标头并且包含下划线,这将很有用。

【讨论】:

    【解决方案2】:

    这毕竟是用户错误。我以错误的格式(IF_MODIFIED_SINCE 而不是If-Modified-Since)将标头发送到应用程序。修复后,它在没有任何额外指令的情况下工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-21
      • 2013-10-31
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 2014-09-18
      • 2016-08-25
      • 1970-01-01
      相关资源
      最近更新 更多