I'm using Nginx on CentOS with a Rails server. I'm confused about how headers get set. If Nginx sets headers and the applicatino server (Ruby on Rails in this case), which one wins out? I have this Nginx server block
server {
listen 80;
server_name www.example.com;
root /home/rails/scale_production/public; # I assume your app is located at this location
location / {
proxy_pass http://scale; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ($request_uri ~* "($\/image\/.*)|(.*\.(ico|gif|jpe?g|png)$)") {
expires 60d;
access_log off;
add_header Pragma public;
add_header Cache-Control "public";
break;
}
}
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
However when I call a URL that matches one of my regex's, I'm not seeing the cache headers getting set ....
localhost:tmp davea$ curl -I "http://www.example.com/people/image/27"
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 03 Mar 2018 18:20:43 GMT
Content-Type: image/jpeg; charset=binary
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Expires: Sun, 03 Mar 2019 18:20:43 GMT
Content-Disposition: inline; filename="Bill Smith"
Content-Transfer-Encoding: binary
Cache-Control: private
ETag: W/"b0c3f986a9c7f967e58733702e71a395"
X-Request-Id: 2f9728bb-3b6f-4d67-9344-afc1e29cacd5
X-Runtime: 0.007781
So I'm wondering why this happens . Am I doing something wrong in my block or are there headers getting set in my application server that are overriding the Nginx headers?