带缓存的 Nginx fall-through url

Nginx fall-through urls with caching

我有 Rails 个应用程序,其路由与首次访问时生成的静态文件相匹配。

如果我在 site.conf 中注释掉此块,一切正常:

 location ^~ /uploads/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

有没有一种方法可以两全其美,让 location 块仅在实际文件存在时才被激活,如果不存在则失败?也许在里面添加try

基于逻辑 "local disk static file vs. dynamic response with backend" 提供响应的最佳实践之一是 try_files:

location ^~ /uploads/ {
  gzip_static on;
  expires max;
  add_header Cache-Control public;
  try_files $uri @backend;
}

location @backend {
  proxy_pass ...
}

查看官方文档here