I have a case where I need to use Nginx map in slightly different way.
I use following to create a variable $blogpath
`map $uri $blogname{
~^(?P<blogpath>/[_0-9a-zA-Z-]+/)files/(.*) $blogpath ;
}`
Next, I want to run another map using:
`map $http_host$blogpath $blogid{
#map lines
}`
Problem is - map doesn't support 2 input parameters. It throws error:
"nginx: [emerg] invalid number of the map parameters ..."
As map is outside server{] block, I cannot use set to create a temporary
variable to combine value of "$http_host$blogpath"
Goal is to get "domain-name.com/first-dir" from URL. If any other nginx
variable can give me entire URL as seen in browser, it will also work.
Please suggest a workaround!
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,231715,231715#msg-231715
on 2012-10-12 14:27
on 2012-10-12 14:57
On Oct 12, 2012, at 16:26 , rahul286 wrote: > > variable to combine value of "$http_host$blogpath" > > Goal is to get "domain-name.com/first-dir" from URL. If any other nginx > variable can give me entire URL as seen in browser, it will also work. > > Please suggest a workaround! What version do you use ? Changes with nginx 0.9.0 29 Nov 2010 ... *) Feature: the "map" directive supports expressions as the first parameter. -- Igor Sysoev http://nginx.com/support.html
on 2012-10-12 15:15
I am using Nginx 1.2.4 So a line like "map $http_host$uri $blogid" is valid one? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231715,231720#msg-231720
on 2012-10-12 15:47
On Oct 12, 2012, at 17:14 , rahul286 wrote: > I am using Nginx 1.2.4 > > So a line like "map $http_host$uri $blogid" is valid one? Yes. This message is issued for internal map parameters. Probably you have space in some first or second paramter. -- Igor Sysoev http://nginx.com/support.html
on 2012-10-12 16:21
I will debug my config again. Thanks. By the way, does map support regex in input parameter? Now or in future? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231715,231722#msg-231722
on 2012-10-12 16:25
On Oct 12, 2012, at 18:21 , rahul286 wrote: > I will debug my config again. Thanks. > > By the way, does map support regex in input parameter? Now or in future? Changes with nginx 0.9.6 21 Mar 2011 *) Feature: the "map" directive supports regular expressions as value of the first parameter. http://nginx.org/en/docs/http/ngx_http_map_module.html map $http_user_agent $mobile { default 0; "~Opera Mini" 1; } -- Igor Sysoev http://nginx.com/support.html
on 2012-10-12 16:37
Sorry for wrong question. I wanted to ask...
map "~ ^/~([^/]*)/.*$)" $userhome{
}
style regex. Where map input string will be $1.
===
Apart from that, inside map:
map $uri $blogname{
~^(?P<blogpath>/[^/]+/)files/(.*)$ $blogpath ;
}
I am not able to use $1. I always have to use a variable like $blogpath.
Is
it by design or a mistake on my end?
I get error: "nginx: [emerg] unknown "1" variable" when I try:
map $uri $blogname{
~^(/[^/]+/)files/(.*)$ $1 ;
}
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,231715,231725#msg-231725
on 2012-10-12 16:44
On Oct 12, 2012, at 18:37 , rahul286 wrote: > Sorry for wrong question. I wanted to ask... > > map "~ ^/~([^/]*)/.*$)" $userhome{ > } > > style regex. Where map input string will be $1. No. "map" is not "location". > > I get error: "nginx: [emerg] unknown "1" variable" when I try: > > map $uri $blogname{ > ~^(/[^/]+/)files/(.*)$ $1 ; > } Digit captures are not supported in map. You have to use named capture. -- Igor Sysoev http://nginx.com/support.html
on 2012-10-12 16:51
Igor Sysoev Wrote: ------------------------------------------------------- > Digit captures are not supported in map. You have to use named capture. Thanks for clarification :-) Is map exception or there are other directives also which do not support Digit captures? I ran into issues in if-location block (mostly an If-evil case). I switched to named capture and it worked nice. Thanks again. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231715,231728#msg-231728
on 2012-10-12 16:56
On Oct 12, 2012, at 18:51 , rahul286 wrote: > to named capture and it worked nice. Some directives support, but digital captures can be implicitly overwritten. With named captures you can control explicitly. -- Igor Sysoev http://nginx.com/support.html
on 2012-10-12 17:15
Yep. When using values across lines, I noticed overwriting. One last question: I think using "P" in named capture e.g. "?P<blogpath>" is old style. But even on nginx 1.2 also some people get error: "pcre_compile() failed: unrecognized character after". It goes away when they update PCRE lib. For better compatibility, is it good idea to use "P" or is there any advantage without "P"? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231715,231734#msg-231734
on 2012-10-12 19:19
On Oct 12, 2012, at 19:14 , rahul286 wrote: > Yep. When using values across lines, I noticed overwriting. > > One last question: > > I think using "P" in named capture e.g. "?P<blogpath>" is old style. But > even on nginx 1.2 also some people get error: "pcre_compile() failed: > unrecognized character after". It goes away when they update PCRE lib. > > For better compatibility, is it good idea to use "P" or is there any > advantage without "P"? No advantage, just readability. ?<name> Perl 5.10 compatible syntax, supported since PCRE-7.0 ?'name' Perl 5.10 compatible syntax, supported since PCRE-7.0 ?P<name> Python compatible syntax, supported since PCRE-4.0 BTW PCRE-7.0 has been released on 19 December 2006, almost 6 years ago. -- Igor Sysoev http://nginx.com/support.html
on 2012-10-13 18:18
Thanks again for more details. For better compatibility, I will use "P" everywhere. :-) Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231715,231765#msg-231765
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.