gpt4 book ai didi

nginx - 如何首先将 nginx 配置为 try_files,如果不存在则遵循 request_uri

转载 作者:行者123 更新时间:2023-12-02 04:55:11 28 4
gpt4 key购买 nike

我们有带有 id 分区和子域的页面缓存。比如说像 ny.site.com/cat/12345la.site.com/dog/234 这样的请求,nginx 需要

  1. 检查文件/cat/ny/1234/5.html是否存在,返回
  2. 否则,只需使用原始request_uri访问应用服务器,即可创建缓存文件

我们设法弄清楚了子域和 id 分区部分,但在 try_files 部分没有得到任何运气。在内部重定向到

时总是出现无限循环错误,例如 rewrite 或 internal redirection cycle

我们的 nginx.conf 文件是这样的



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;

有什么提示吗?谢谢!

更新:我尝试了以下。 Nginx 在文件系统中寻找 $request_uri(例如/cat/12345),而不是访问应用服务器。有什么想法吗?

try_files $uri @old;
location @old {
rewrite ^ $request_uri break;
}

最佳答案

试试这个

location ^~ ^/cat/([0-9]{4})([0-9]{1,4}) {

try_files "/cat/ny/$1/$2.html" @app_server;

}
location @app_server{

# pass this to your app server for processing.

}
  1. 使用 ^~,因为这也将包括像/cat/12345/(结束斜杠)这样的边缘情况。
  2. 只需确定您是想要 $uri(没有查询字符串)还是 $request_uri(其中包含查询字符串)。

关于nginx - 如何首先将 nginx 配置为 try_files,如果不存在则遵循 request_uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18117625/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com