Why nginx adds the trailing slash and redirects the request, when I check the variable of the regular season?

Hi all. There is one nginx, and it behaves in an unexpected way.
Goal: to enable access for requests from a specific IP at a specific location. Default access_log is turned off.

Config:
http {
 map $remote_addr $is_my_ip {
 default 0;
 "1.2.3.4" 1;
}
 # further config...
}
server {
 # here server_name and stuff
 location ~ ^/1/(.+\.mp3)$ {
 if ($is_my_ip) {
 access_log /var/log/nginx/my.log;
}
 alias /var/storage1/$1;
}
}

So, as in the example above, everything works fine. You can not use the map and check the variable directly in the if, the essence will not change and will work exactly the same.

And if I write so:
map $remote_addr $is_my_ip {
 default 0;
 "~*^1\.2\.3\.4$" 1;
}

The request, for example on http://server_name/1/blah/blah.mp3 redirectet on http://server_name/1/blah/blah.mp3/ and then returns 404.

If you check the line, then everything is OK, but if the regular season, then added the slash, why?
March 12th 20 at 08:40
1 answer
March 12th 20 at 08:42
server {
 # here server_name and stuff
 location ~ ^/1/(?<path>.+\.mp3)$ {
 access_log /var/log/nginx/my.log combined if=$is_my_ip;
 alias /var/storage1/$path;
}
}

Find more questions by tags Regular expressionsNginx