nginx strips last-modified and if-modified-since headers but my rails app needs them

本秂侑毒 提交于 2020-01-15 09:34:08

问题


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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/10738118/nginx-strips-last-modified-and-if-modified-since-headers-but-my-rails-app-needs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!