2016-03-07 53 views
1

我需要nginx的重写规则(转换片段以得到paramters)

/secure/token/timestamp/path/to/the/resource/ 

在这个格式被改写:

/s/path/to/the/resource/?st=token&e=timestamp 

什么,我试图做的是:

location /secure/(?<token>)/(?<timestamp>)/(?<path>) { 
    rewrite^/s/$path/?st=$token&e=$timestamp 
} 

但它显然不工作。这个语法似乎并不正确。我如何在nginx规则中使用url来玩这个游戏?

编辑: 现在尝试是这样的:相同的结果:

 location /secure/(.*)/(.*)/(.*) { 
     rewrite^/s/$3?st=$1token&e=$2timestamp; 
    } 

回答

1

你有多个问题。您已将前缀位置与正则表达式位置混淆。您的命名捕捉不包含任何内容。而你的数字捕捉可能太宽泛。

有关位置语法,请参见this

你或许应该使用前缀的位置,然后捕获在改写:

location /secure/ { 
    rewrite ^/secure/([^/]*)/([^/]*)/(.*)$ /s/$3?st=$1&e=$2 last; 
}