-1

I'm trying to remove the Last_Modified headers from Nginx responses.

I've read that this can be achieved by this line in the config:

 add_header Last-Modified '';

This works, however for some reason our CORS Access-Control headers are then no longer sent. I'm assuming this might be a bug (we are on v1.2.6), but would like others' opinion.

Why is this happening? and What can I do to remove Last-Modified, but keep the Access-Control headers?

Our config file looks like this:

http {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';

    server {
        listen 80;
        server_name xxxxxxxxxxxxxxxxx;
        root xxxxxxxxxxxxxxxxx

        expires 1y;
        log_not_found off;

        add_header Last-Modified '';
    }
}
  • 1
    RTFM. There could be several add_header directives. These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level. – Alexey Ten Oct 21 '15 at 8:42
5

The nginx add_header directive is a bit... special, and its behaviour when being inherited from a less-specific scope is a trap for the unwary. As the documentation states:

There could be several add_header directives. These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level.

This means that, once you specify any add_header directives in a given configuration block, you must also specify any add_header directives from less-specific scopes which you want to retain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.