nginx 配置 try_file 求解

2016-12-28 16:49:29 +08:00
 kwok

配置文件如下:

server {
  listen 80;
  server_name example.com;
  root /home/foo;
  location / {
    proxy_pass http://localhost:8888;
  }
  location ~ ^/static/(.*)$ {
   try_files $document_root/web/static/$1 $document_root/view/dist/$1 $document_root/business/dist/$1 =800;

  #  if (-f $document_root/web/static/$1) {
  #   return 601;
  #  }
  #  if (-f $document_root/view/dist/$1) {
  #   return 602;
  #  }
  #  if (-f $document_root/busines/dist/$1){
  #    return 603;
  #  }
   }
 location @fallback {
   proxy_pass http://localhost:8888;
 }
}

如果注释 指令 try_files , 反注释 if ,那么我就会收到 601 , 602 的错误码(说明文件存在) 但是 使用 try_file 就是找不到文件?; 请问各位 V 友,哪里出错了?

在 Google 找了一个下午了,还是没有找到答案。

先谢谢各位,给于帮助了朋友了!

1857 次点击
所在节点    问与答
2 条回复
lhbc
2016-12-28 17:02:31 +08:00
这个配置有点奇葩,看下 error_log 吧
ahu
2016-12-28 20:39:33 +08:00
$1 改为 $uri 看看

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/330784

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX