gpt4 book ai didi

http - NGINX try_files 回退

转载 作者:可可西里 更新时间:2023-11-01 16:26:34 28 4
gpt4 key购买 nike

我有这个文件夹结构:

/document/root/
|-- main
`-- wishlist

我想让我的 nginx 像这样工作:如果我将浏览器指向 example.com/wishlist,它将在 上显示 index.html >wishlist 文件夹。如果我将浏览器指向 example.com,我希望它回退到 main/index.html(当然还有相关的 main/style.css 和主目录中的其他文件)。

我不想为根目录下的每个文件夹都写一个位置规则,所以我希望它尽可能通用。我找到了 this question,它帮助我完成了大部分工作,但有些东西不起作用:如果我将浏览器指向 wishlist/index.html,它会完美运行。但是,如果我删除 index.html 并将其指向 example.com/wishlist,浏览器将返回 404。我当前的 Nginx 配置如下。有人能指出我正确的方向吗?谢谢。

server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /document/root/main;

location ~ ^/([^/]+)(/.+)?$ {
if (!-d "$document_root/$1") {
return 404;
}
try_files /$1$2 /main$2 =404;
}
}

最佳答案

保持简单:

server {
root /document/root/main/;
index index.html;

location /wishlist {
root /document/root/;
}
}

关于http - NGINX try_files 回退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638031/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com