gpt4 book ai didi

redirect - 如何在外部文件中包含重定向?

转载 作者:行者123 更新时间:2023-12-05 00:22:52 24 4
gpt4 key购买 nike

我需要在域上设置大约 5-6k 重定向(用于站点迁移),而且我是 nginx 的新手。我有一些测试重定向在域的主 .conf 文件中工作。但我不想在主 .conf 文件中有 5k+ 重写,所以我被告知我可以在 .conf 中包含一个外部文件以保持它干净,所以我的主 .conf 像这样

server {
listen.....etc
etc

rewrite ^oldurl newurl permanent;
rewrite ^oldurl newurl permanent;
include /etc/nginx/conf.d/redirects.conf;

location ....etc
etc
}

然后在redirects.conf中我只有
rewrite ^oldurl newurl permanent;

但是当我尝试重新启动 nginx 时出现错误:
"rewrite" directive is not allowed here in /etc/nginx/conf.d/redirects.conf:1 

谢谢

最佳答案

好的,问题是我正在调用外部文件 redirects.conf,因为每个以 .conf 结尾的文件都被视为站点配置文件。
我将其更改为 sitename.redirects,现在它工作正常

关于redirect - 如何在外部文件中包含重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253130/

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