LeeReamond
V2EX  ›  问与答

nginx 配置静态目录路由失效,哪里写错了吗?

  •  
  •   LeeReamond · Dec 8, 2021 · 986 views
    This topic created in 1620 days ago, the information mentioned may be changed or developed.

    配置如下:

    server {
    	...
        location ~* \.(css|gif|ico|jpg|js|png|ttf|woff)$ {
          root /www/wwwroot/example.com/static;
          try_files /www/wwwroot/example/static/$uri $uri/ /404.html;
        }
    }
    

    想要寻找的文件是 favicon.ico ,也确保 /www/wwwroot/example.com/static 这个文件夹里有 favicon.ico ,这个路由也是排在首位的,访问 example.com/favicon.ico 的时候后端检查了一下实际请求的路由是 /404.html ,似乎是 try_files 失败了,这咋回事?

    2 replies    2021-12-08 21:44:54 +08:00
    maichael
        1
    maichael  
       Dec 8, 2021
    你都配置 root 了,try_files 就直接 $uri 就好了。
    LeeReamond
        2
    LeeReamond  
    OP
       Dec 8, 2021
    @maichael 试了试,改成 tryfiles $uri $uri/ /404.html 这样就行了。之前那个好像也能跑,是 cdn 的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2919 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:00 · PVG 15:00 · LAX 00:00 · JFK 03:00
    ♥ Do have faith in what you're doing.