Welcome! Log In Create A New Profile


Nginx issue when using regex in a map

Posted by Dan_v 
Nginx issue when using regex in a map
June 01, 2020 03:17AM
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;
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 82
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready