rewrite - How to configure nginx to try_files first, if not exists follow the request_uri -
we have page caches id partitioning , subdomain. requests ny.site.com/cat/12345
or la.site.com/dog/234
, nginx need to
- check if file
/cat/ny/1234/5.html
exists, return it - otherwise, use original
request_uri
hit app server, , cache file created
we managed figure out subdomain , id partitioning part, didn't luck on try_files part. indefinite loop errors rewrite or internal redirection cycle while internally redirecting to
our nginx.conf file like
rewrite "/cat/([0-9]{4})([0-9]{1,4})" /system/cache/cat/$subdomain/$1/$2.html break; rewrite "/cat/([0-9]{1,4})" /system/cache/cat/$subdomain/$1.html break; try_files $uri $request_uri;
any hints? thanks!
update: tried following. nginx looking $request_uri (e.g., /cat/12345) in file system instead of hitting app server. thoughts?
try_files $uri @old; location @old { rewrite ^ $request_uri break; }
try this
location ^~ ^/cat/([0-9]{4})([0-9]{1,4}) { try_files "/cat/ny/$1/$2.html" @app_server; } location @app_server{ # pass app server processing. }
- use ^~ include edge case /cat/12345/ (ending slash).
- and sure whether want $uri (which without query string) or $request_uri ( contains query string).
Comments
Post a Comment