Nested location block for merging config returns 404?
Jonathan Matthews
contact at jpluscplusm.com
Tue Jan 21 14:10:28 UTC 2014
On 21 January 2014 13:59, WheresWardy <nginx-forum at nginx.us> wrote:
>> Your line
>>
>> location \.(txt|css) {
>>
>> looks like a regex, but you're not telling nginx it /is/ a regex. I
>> wouldn't expect anything to work until you fix that.
>
> Apologies, that was a typo during simplification of my config. I do indeed
> have a ~ in my nested location block, and it's definitely matching
> correctly.
>
> Everything else you've specified seems to fit my observed behaviour, so
> think it's just that my use case doesn't fit with the inheritance rules as
> they stand. Thanks for your help!
No problem. You could look at using a map to achieve the config
deduplication you're aiming for. Something like this (typed, but not
tested or syntax-checked!)
------------------------------------
http {
map $uri $map_output {
default "";
~ \.txt "value2";
~ \.css "value2";
}
server {
location ~ /(dir1/)?dir2/ {
add_header X-My-Header value1;
add_header X-My-Static $map_output;
proxy_pass http://myproxy;
}
}
}
------------------------------------
This will also have the effect of wiping out inbound X-My-Static
headers, which you could get round by referencing them in the default
map output if you really needed them to be passed through ...
Jonathan
More information about the nginx
mailing list