Nginx位置匹配正则表达式不起作用 [英] Nginx location match regex not working

查看:1128
本文介绍了Nginx位置匹配正则表达式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将位置与以下提到的模式匹配,我想将expires标头设置为24小时.但它不起作用.如果我只使用下面提到的正则表达式,它会起作用:

I am unable to match location with below mentioned pattern, I want to set expires header to 24 hrs. but it is not working. It works if I just use below mentioned regex :

location ~* .*abc\.php.* {
expires 24h;
}

下面的示例不起作用.

location ~* .*abc\.php.*xyz=detail.*login_something=.* {
expires 24h;
}

"abc.php"和&之间存在很多内容. "xyz = detail"& "login_something =",所以我只能使用.*.

There is lot of content in between and after of "abc.php" & "xyz=detail" & "login_something=" so I have to use .* only.

提前谢谢!

推荐答案

有多种方法可以实现您要执行的操作,但是最简单的方法是将mega regex应用于包含整个URI(包括查询字符串).这将是$request_uri

There are multiple ways to achieve what you are trying to do, but the simplest method is to apply your mega regex to a variable that contains the entire URI (including the query string). This would be $request_uri

第二个问题是如何反复操作expires,而不是使用多个块,而不必在每个模块中重新实现PHP指令,只需使用map指令

The second problem is how to manipulate expires and again, rather than use multiple blocks and have to reimplement PHP directives in each one, just use the map directive as detailed in the expires documentation.

例如:

map $request_uri $expires {
    default                                   off;
    ~*abc\.php.*xyz=detail.*login_something=  24h;
}

server {
    ...
    expires $expires;
    ...
}

这篇关于Nginx位置匹配正则表达式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆