Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Nginx issue when using regex in a map

$
0
0
I'm stuck on what seems to be a trivial problem when generating a rewrite url using a map.

I've tried multiple regex, but can't get the map to match for both conditions.

$some_var is a variable that may or may not be passed from an upstream server and I want to rewrite a location, if it's present or not.

This is what I've got, but it's not working. Any help greatly appreciated!

map $some_var $rewrite_url {

# if $some_var has any value I want to match this (this never matches)
~(.*) /path/to/thing2.js;

# if $some_var is not present I want to match this (this always matches)
default /path/to/thing.js;
}

# elsewhere in server config
location /getThing.js {
rewrite ^ $rewrite_url;
}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>