简体   繁体   中英

Nginx location match regex not working

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;
}

Below example does not work.

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

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

Thanks in advance!

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

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 .

For example:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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