E-tags are missing in the response headers with rails 3.2 / nginx / phusion passanger

I have a very simple controller with e-tags:

class EtagsController < ApplicationController before_filter :require_user def index if stale?(:etag => current_user) render :layout => false end end end 

When I run this in my local development environment, the first request is 200 with ETag in the response. The second request returns an ETag, and I get a 304 response as expected.

However, when this is done in my intermediate or production environment, there is no ETag in the response.

Here are the request and response headers from my staging environment:

 Request URL: /etags Request Method:GET Status Code:200 OK Request Headers Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Cookie:__utma=169165539.1455374302.1372358226.1372358226.1372358226.1; __utmb=169165539.1.10.1372358226; __utmc=169165539; __utmz=169165539.1372358226.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); user_credentials=4ffa15df84112d22434f121eed06c59a5c32cb9ab72cf6bf1e952a3993201b5dec2917a028d20d4b63c70a84c6a290c4d5c4673ce967efec6f139c161850bc37%3A%3A101; _session_id=d21671b70349653406442ee0716633b2 User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 Response Headers Cache-Control:must-revalidate, private, max-age=0 Connection:keep-alive Content-Encoding:gzip Content-Length:65 Content-Type:text/html; charset=utf-8 Date:Thu, 27 Jun 2013 18:37:10 GMT Server:nginx/1.4.1 + Phusion Passenger 3.0.19 Status:200 X-Powered-By:Phusion Passenger (mod_rails/mod_rack) 3.0.19 X-Rack-Cache:miss X-Request-Id:620c1ab99a1af7b6dde62cee77fc59fe X-Runtime:0.205884 X-UA-Compatible:IE=Edge,chrome=1 

I'm at a dead end. Why doesn't my staging environment match the ETag in my controller?

Technologies used:

  • Phusion Passenger 3.0.19
  • nginx 1.4.1
  • Rails 3.2.13

Thannks

+4
source share
2 answers

It seems that nginx> 1.3 will ignore the e-tag from your application server if gzip is enabled for nginx. We did not find a solution in nginx that would allow us to go through the electronic tags from the application server and gzip response. I believe weak electronic tags may work for this, but nginx does not currently support them.

+4
source

Nginx still does not support weak etags. Maybe in 1.7.x:

http://forum.nginx.org/read.php?29,249380,249740#msg-249740

This answer makes it possible to convert your middleware into weak etags:

Weak ETAGs in Rails?

+1
source

Source: https://habr.com/ru/post/1488565/


All Articles