简体   繁体   中英

nginx proxy_cache_key using regex

I am trying to match specific parts of $uri using proxy_cache_key in nginx 1.12 for these requests where different file names (with no arguments) actually have the same file contents. :(

2018-04-02T21:25:37+00:00  MISS /bein1/1/media_w1751476191_2333.ts
2018-04-02T21:25:37+00:00  MISS /bein1/1/media_w2137194067_2333.ts
2018-04-02T21:25:38+00:00  MISS /bein1/1/media_w1023873154_2333.ts

I have tried the following:

location ~ ^/bein1/(.*)/media_(.*)_(.*).(ts)$ {
    proxy_cache_valid 200 302 60s;
    proxy_cache_key "/bein1/$1/media_$3.ts";
    proxy_pass http://origin;
    add_header "X-Hls-Cache-Status" "Cached TS";
}

But I still could not match the specified URI.

Can any one can help me please?

Try with something like this:

location ~ ^/bein1/([-_a-zA-Z0-9/]+)/media_([-_a-zA-Z0-9/]+)_([0-9]+).ts$ {
   proxy_cache_key "/bein1/$1/media_$3.ts";
   proxy_cache_valid 200 302 60s;
   proxy_pass http://origin;
}

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