V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
xiaochena
V2EX  ›  NGINX

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

  •  
  •   xiaochena · Oct 24, 2024 · 2342 views
    This topic created in 550 days ago, the information mentioned may be changed or developed.

    在请求如 /_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";
        }
    
    4 replies    2024-11-03 03:17:35 +08:00
    proxytoworld
        1
    proxytoworld  
       Oct 24, 2024
    用 ai 解释就行了,刚试了一下。
    newaccount
        2
    newaccount  
       Oct 24, 2024
    break
    开 debug
    看其他配置
    这标题懒得认真答
    wogogoing
        3
    wogogoing  
    PRO
       Oct 24, 2024
    把:
    alias /app/.next/static/;
    改为:
    root /app/.next/static/;
    autoindex off;

    试一下吧,我没记错的话,应该可以。
    devopsdogdog
        4
    devopsdogdog  
       Nov 3, 2024 via Android
    不支持二次重写。没记错的话,楼上的应该可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   956 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 20:48 · PVG 04:48 · LAX 13:48 · JFK 16:48
    ♥ Do have faith in what you're doing.