Eugene
Eugene

Reputation: 1170

Disabling Cache-Control in Nginx for certain IPs

Static files on my server served with browser caching via Cache-Control headers:

location ~* \.(css|js|gif|jpe?g|png)$ {
        expires 1h;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

Is it possible to disable this header for certain IPs so they would not cache any files?

P.S. I need it for users who log in as administrators to see the last changes.

Upvotes: 1

Views: 190

Answers (1)

Richard Smith
Richard Smith

Reputation: 49812

The expires directive can be controlled by a variable, usually generated by a map directive. See this document for details.

For example:

map $remote_addr $expires {
    default     1h;
    10.1.2.3    -1;
}
server {
    ...
    location ~* \.(css|js|gif|jpe?g|png)$ {
        expires    $expires;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

It is assumed that the add_header statements can remain, even if expires is set to -1 to disable the caching.

Upvotes: 1

Related Questions