简体   繁体   English

在 Nginx request_uri 中使用变量

[英]Using variables in Nginx request_uri

Good morning programmers, I'm trying to protect a file, and for that I just want to allow the request_uri that I define.程序员们早上好,我正在尝试保护一个文件,为此我只想允许我定义的 request_uri。 Example:例子:

if ($request_uri !~* "d=123") {
return 403;
}

In this case, that example works, but I would like to do something like this:在这种情况下,该示例有效,但我想做这样的事情:

set $teste 123;
if ($request_uri !~* "d=$teste") {
return 403;
}

So I want to make it via variables, is that possible?所以我想通过变量来实现,这可能吗? Cause I already tested a bunch of examples and none of them worked.因为我已经测试了一堆示例,但没有一个有效。

PS: I'm using OpenResty (Nginx+Lua) so if there is a possible solution with lua I would accept it too. PS:我使用的是 OpenResty (Nginx+Lua),所以如果有可能的解决方案 lua 我也会接受。

Assuming d is your query argument and 123 is it's value, you could try something like this:假设d是您的查询参数并且123是它的值,您可以尝试这样的事情:

set $teste 123;
if ($request_uri ~* "[?&]d=([^&]*)") { set $d $1; }
if ($d != $teste) {
    return 403;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM