Score:0

Setting Nginx expires epoch header selectively

cn flag

I have a folder containing imagery on my server that is used to service both a mobile app, via a CDN, and to work with a backend webapp used to manage the content delivered to the app. For the latter - the backend webapp - I want to ensure that images delivered from the folder in question are not cached by the browser so I can show updated versions in the backend app as soon as they have been updated by their author. The CDN pulls the same images for delivery to the mobile app and has its refresh settings at 30 minutes so it does not deliver badly dated content imagery.

My question - how can I configure Nginx so it injects the expires epoch header only for requests originating from the webapp. Part of the answer to this question is in this SO thread. Is there a way to modify the solution proposed there so it examines the referrer prior to injecting the header? So, for instance all requests originating from https://example.com/backoffice are responded to with the expires epoch header while others - e.g. those coming from the CDN pull requests - are not.

Michael Hampton avatar
cz flag
There is important information missing: Exactly what criteria do you want to match?
cn flag
See my edit. Hopefully, that explains what I am after.
Score:2
cz flag

A simple if ought to be sufficient here:

server {

    location ... {

        if ($http_referer ~* ^https://example.com/backoffice) {
            expires epoch;
        }

    }

}

Keep in mind that in general it is vastly preferable for your web application to make caching decisions and respond with the appropriate directives.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.