Score:0

NGINX include json file at both locations

br flag

I have the following nginx code which I would like to have json files passing through both locations. Having the following code, json files passes only via the second location. What is needed in order to have both locations "enabled" for json. I want to make sure that the first location contains the /new URI (+several other sub-URIs).

location /new/ {
proxy_http_version     1.1;
proxy_pass http://new_upstream;
}


location ~* \.(?:jpg|jpeg|json|fs)$ {
proxy_pass http://upstream;
}
us flag
Your question is a bit unclear, what exactly do you mean by "json files passing through both locations"? Can you give examples of request URLs and what each URL should serve?
br flag
first location: <URL>/new/test1/test.json second location: <URL>/one/use.json
Score:0
us flag

As explained in the nginx documentation for location, nginx first matches exact matches (= /path), then prefix matches (/path), and remembers best match.

Then it proceeds to check for regular expression matches, and uses it if something is found.

If one wants to prevent regular expression matches for a location, one needs to use the ^~ specifier in the location:

location ^~ /new/ {
    proxy_http_version        1.1;
    proxy_pass http://new_upstream;
}

location ~* \.(?:jpg|jpeg|json|fs)$ {
    proxy_pass http://upstream;
}

However, this configuration forces all requests with prefix /new to be processed by that block. No JPG / JPEG / JSON / FS extensions will be served by the second block for /new block.

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.