0

I want to cache the content from specific location only. But when i am trying to use regular expression, it is not caching.

proxy_cache_path /AINginxService/nginx-1.16.1/cache/ levels=1:2 keys_zone=one:10m max_size=8g inactive=5d use_temp_path=off;

proxy_cache one;    

    location ~* /v1/mydata/studies/[0-9.]+/series/[0-9.]+/instances/[0-9.]+/rendered {
        #rewrite http://([^/]+)/rendered break;
        proxy_cache_valid 200 120h;
        proxy_pass http://127.0.0.1:9000/v1/mydata;
        proxy_set_header Host $host;
        proxy_pass_request_headers on;
        proxy_http_version 1.1;
        proxy_set_header Origin "";
        proxy_connect_timeout 1d;
        proxy_send_timeout 1d;
        proxy_read_timeout 1d;
        send_timeout 1d;
    }

    # Rest api entry point
    location /v1/mydata {
        #proxy_cache_valid 200 120h;
        proxy_pass http://127.0.0.1:9000/v1/mydata;
        proxy_set_header Host $host;
        proxy_pass_request_headers on;
        proxy_http_version 1.1;
        proxy_set_header Origin "";
        proxy_connect_timeout 1d;
        proxy_send_timeout 1d;
        proxy_read_timeout 1d;
        send_timeout 1d;
    }
}

PS: If I uncomment proxy_cache_valid in /v1/mydata, it caches everything.
NOTE: Possible URL patterns

 1. /v1/mydata/studies/{study_id}/       # Not to cahce
 2. /v1/mydata/studies//series/{series_id}/      # Not to cache
 3. /v1/mydata/studies//series/{series_id}/instances/{instance_id}/    # Not to cahce
 4. /v1/mydata/studies//series/{series_id}/instances/{instance_id}/rendered     # Cache this
  • The problem is the `/v1/mydata` on the end of the `proxy_pass` statement. It looks redundant, so you should probably just remove it from **both** `proxy_pass` statements. Use: `proxy_pass http://127.0.0.1:9000;` – Richard Smith May 16 '20 at 19:30
  • Thank you @RichardSmith , it worked for me...but why was this issue present? Since all my request have v1/mydata in url. – Shashank Dixit May 19 '20 at 19:54
  • The `proxy_pass` statement works differently when inside a regular expression location block. See [this document](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass). – Richard Smith May 19 '20 at 19:57
  • Thank you for helping me out... Really appreciated. – Shashank Dixit Jul 07 '20 at 19:55

0 Answers0