V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
kwok
V2EX  ›  问与答

nginx 配置 try_file 求解

  •  
  •   kwok · 2016-12-28 16:49:29 +08:00 · 1752 次点击
    这是一个创建于 2682 天前的主题,其中的信息可能已经有所发展或是发生改变。

    配置文件如下:

    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 找了一个下午了,还是没有找到答案。

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

    2 条回复    2016-12-28 20:39:33 +08:00
    lhbc
        1
    lhbc  
       2016-12-28 17:02:31 +08:00
    这个配置有点奇葩,看下 error_log 吧
    ahu
        2
    ahu  
       2016-12-28 20:39:33 +08:00
    $1 改为 $uri 看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   741 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 21:30 · PVG 05:30 · LAX 14:30 · JFK 17:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.