问题描述
My Rails 3.2应用程序使用 - 通过 #stale?
- If-Modified-Since
请求中的HTTP标头并在响应中使用 Last-Modified
标头来决定是否应该动态生成一些数据。这在开发中非常有效(无论是使用webrick还是unicorn_rails),因为 curl -D headers.txt
表明如果正确 If-Modified-Since
提供的值为304响应,而 Last-Modified
标头则以请求数据的形式发送。
My Rails 3.2 app uses — via #stale?
— If-Modified-Since
HTTP header in the request and Last-Modified
header in the response to decide whether it should generate some data dynamically. This works extremely well in development (whether using webrick or unicorn_rails) as curl -D headers.txt
shows that if the correct If-Modified-Since
value is provided a 304 response is sent, while the Last-Modified
header is otherwise sent along the request data.
不幸的是,一旦部署在nginx之后, If-Modified-Since
(提供正确的标头值)都传递给unicorn - 因此Rails应用程序 - 也不会将 Last-Modified
传播到客户端:无条件地生成请求,并且响应永远不会包含正确的标头。
Unfortunately once deployed behind nginx, neither If-Modified-Since
(providing the correct header value) is passed to unicorn — and thus the Rails app — nor Last-Modified
is propagated to the client: the request is unconditionally generated and the response never contains the proper headers.
推荐答案
事实证明,nginx实际上并没有剥离任何东西。仪表显示控制器收到 If-Modified-Since
。 Rails #stale?
收到包含错误结果的请求,导致 nil
参数,静默吞噬它忽略与 If-Modified-Since
的比较和定位 Last-Modified
到 nil
。
It turns out nginx was actually not stripping anything. Instrumentation showed that If-Modified-Since
was received by the controller. Rails #stale?
was receiving a request containing bad results, which resulted in a nil
argument, swallowing it silently and subsequently ignoring comparisons to If-Modified-Since
and positioning Last-Modified
to nil
.
这篇关于nginx剥离最后修改和if-modified-since标头,但我的rails应用程序需要它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!