V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
xiaochena
V2EX  ›  NGINX

虚心请教一个有关于 nginx 配置的问题

  •  
  •   xiaochena · 16 小时 43 分钟前 · 378 次点击

    在请求如 /_next/static/media/page-main-image.0b61c706.png 这样的文件时

    这段配置可以正常运行

        location ~* /_next/static/.*(js|css|png|jpg|jpeg|svg|gif|ico|ttf|webp)$ {
          rewrite /_next/(.*) /.next/$1 break;
          try_files $uri $uri/;
          expires 1y; # 设置缓存时间为 1 年
          add_header Cache-Control "public";
        }
    

    这段配置却找不到文件、响应体还会变成 308 重定向

        location ~* /_next/static/.*(js|css|png|jpg|jpeg|svg|gif|ico|ttf|webp)$ {
          alias /app/.next/static/; # 将请求路径 /_next/static/ 映射到文件系统的 /app/.next/static/
          expires 1y; # 设置缓存时间为 1 年
          add_header Cache-Control "public";
        }
    
    3 条回复    2024-10-24 22:33:14 +08:00
    proxytoworld
        1
    proxytoworld  
       16 小时 35 分钟前
    用 ai 解释就行了,刚试了一下。
    newaccount
        2
    newaccount  
       16 小时 0 分钟前
    break
    开 debug
    看其他配置
    这标题懒得认真答
    wogogoing
        3
    wogogoing  
       8 小时 54 分钟前
    把:
    alias /app/.next/static/;
    改为:
    root /app/.next/static/;
    autoindex off;

    试一下吧,我没记错的话,应该可以。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1235 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 23:27 · PVG 07:27 · LAX 16:27 · JFK 19:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.