Fwd: nginx.conf + Location + regular expression

Sergey Brester serg.brester at sebres.de
Wed Jan 24 14:00:37 UTC 2018


 

Although you've used a wrong list for your question (this is development
mailing list not a forum for howto's),
but because I've ATM a free minute, here you go: 

You CANNOT use variables in nginx location [2] uri-pattern (no matter
regexp or static URI), 

so the following code:

```
 location ~ ^.../$reg_exp/...$ {...

```

does not substitute the variable (the char $ - is just a dollar
character here).

The same is valid for directive if [3], so `if ($uri ~*
".../$reg_exp/...") { ...` does not interpolate `$reg_exp`

as variable.

So what you are trying is impossible in nginx.

Just write it direct in location-regex (without variable) or use some
macros resp. some custom module, 
that could do it. 

In addition please note this. [4]

Regards,
sebres.

Am 24.01.2018 14:22, schrieb fx.juhel at free.fr: 

> Hello nginx DEV TEAM ! How are you ?
> 
> I would like to know how can I do to detect this type of directory name with regexp : (Guid 8-4-4-4-12) => "be93d4d0-b25b-de94-fcbb-463e6c0fe9cc"
> 
> How can I use $reg_exp in location
> I do this : 
> 
> set $reg_exp "[0-9a-fA-F]{8}?-[0-9a-fA-F]{4}?-[0-9a-fA-F]{4}?-[0-9a-fA-F]{4}?-[0-9a-fA-F]{12}"; 
> 
> location ~ ^/locale/Project/Documents/(reg_exp)/(?<document>.*)$ {
> 
> }
> 
> Thank you very well for your reply 
> 
> François - Xavier JUHEL
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel [1]
 

Links:
------
[1] http://mailman.nginx.org/mailman/listinfo/nginx-devel
[2] http://nginx.org/en/docs/http/ngx_http_core_module.html#location
[3] http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if
[4] http://nginx.org/en/docs/faq/variables_in_config.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20180124/dd9401a7/attachment.html>


More information about the nginx-devel mailing list