如何在外部文件中包含重定向?
How to include redirects on external file?
我需要在域上设置大约 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,现在可以正常使用了
我需要在域上设置大约 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,现在可以正常使用了