1

I've installed nginx/1.10.3 (Ubuntu) and changed the original config file so that it is only slightly different at the top of the http context:

http {
    add_header 'Cache-Control' 'no-cache';

and this is working. I will see 'no-cache' in the response headers when I access the index.html (tested with / and /index.html). And I can add more attributes like 'no-store', that will also work, it's really working here.

But I'd like to restrict the no-cache to only the index.html, and I can't get this to work.

http {
    server {
        location = /index.html {
            add_header 'Cache-Control' 'no-cache';
        }
    }

does not work, no 'no-cache' appears in the response headers (tested with / and /index.html). Also not working are location / { ..., and location ~ and location ~* with a regexp.

I'm lost here. I'll reinstall nginx and check if there is a typo. Am I doing this correctly at all?

Edit: I purged and reinstalled nginx, did the same things again, got the same result.

sorry
  • 11
  • 1
  • 3
  • Is that your http block configuration in it's entirety? If you haven't set up any directives specifying which locations/content/file types can be cached and how long those cached resources can be considered fresh then what exactly are you expecting Nginx to add here? – miknik Jul 10 '18 at 23:43
  • I had put it into the wrong configuration file, the location context seems to work here only in sites-availale/default. – sorry Jul 10 '18 at 23:59

1 Answers1

0

I've put the lines into /etc/nginx/sites-available/default now and it works. Previously I had made the location context in /etc/nginx/nginx.conf and that seems to be wrong.

sorry
  • 11
  • 1
  • 3
  • 1
    It's not "wrong" as such, you need to imagine the two files as actually one big file. Everything in nginx.conf applies to every site your Nginx instance is hosting, then this line in halfway down `include /etc/nginx/sites-enabled/*;` tells Nginx to now also process all the files in that folder to find rules specific to each individual site/server – miknik Jul 11 '18 at 00:03