小编l2y*_*sho的帖子

nginx 如何在 try_files 中处理 =404 回退

我有一个示例 Web 服务器,在 www 目录中只有一个 index.html 文件。我可以使用以下配置设置 nginx:

location /subfolder {
     alias /data/www;
     try_files $uri $uri/ /index.html;
}
Run Code Online (Sandbox Code Playgroud)

In browser I can see correct response on my local domain test.local/subfolder, also test.local/subfolder/something returns a default nginx page (it is normal because root is not set)

if I change a configuration to

location /subfolder {
     alias /data/www;
     try_files $uri $uri/ /index.html =404;
}
Run Code Online (Sandbox Code Playgroud)

response to test.local/subfolder is still correct, but test.local/subfolder/something and all URI with /subfolder prefix return a index.html …

nginx nginx-location

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

nginx ×1

nginx-location ×1