args and rewrite vars always empty

Maxim Dounin mdounin at mdounin.ru
Fri May 24 11:38:46 UTC 2019


Hello!

On Fri, May 24, 2019 at 10:43:35AM +0000, User via nginx wrote:

> On 5/24/19 9:50 AM, Maxim Dounin wrote:
> > The first line shows actual matching - regular expression itself
> > and the string it matches, and the second one shows the result. 
> > The above two lines were obtained with the following trivial
> > configuration:
> 
> Yes, thanks. I clearly understand it all. I know how regex work and $1
> expected result must be directory name. My "rewrite_log on" logs
> attached at the first message. It's almost the save server {}
> configuration. Currently:

There were no first line in your original message, hence the 
question.

> server {
>   listen SERVERIP:80;
>   server_name domain.com;
>   error_log  /var/log/nginx/domain.com.nginx notice;
>   access_log off;
>   rewrite_log on;
>   index index.php;
>   root /home/user/domain.com;
> 
>   location /product/ {
>    rewrite ^/product/(.*)/$ /$1/$2/$3/$0/end.txt last;
>   }
> 
> }
> 
> 
> Look at this! My little investigation. I try to find where $1 is lost
> and for this purposes added other possible variables $0 $2 $3 from
> regex. And what I see? $0 is not empty and guess what?  Seems that it
> contain some of my root user command from shell. All other variables are
> empty as I wrote at the first post.

There is no special $0 variable in nginx, and the above 
configuration is expected to produce:

nginx: [emerg] unknown "0" variable

error on start (just checked with 1.10.3 to be sure).

If it doesn't for some reason, and nginx starts - this means that 
either the $0 variable is defined elsewhere, or there is something 
wrong with nginx you are using (wierd 3rd party modules/patches?).

Please show "nginx -V" to find out how nginx was compiled, and 
"nginx -T" for full configuration.

[...]

> And I found that yes, nginx not build with pcre library, but seems it
> execute it at the shell each time:
> 
> https://github.com/nginx/nginx/blob/4bf4650f2f10f7bbacfe7a33da744f18951d416d/src/core/ngx_regex.h
> 
> And it return not expected results for some reasons.

No, your understanding is wrong.  If nginx is compiled without 
PCRE, the rewrite directive will not be available at all.  And 
nginx never tries to execute anything at the shell.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list