【问题标题】:How to include redirects on external file?如何在外部文件中包含重定向?
【发布时间】:2015-05-28 23:22:51
【问题描述】:

我需要在域上设置大约 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 

谢谢

【问题讨论】:

    标签: redirect nginx


    【解决方案1】:

    好的,问题是我调用了外部文件 redirects.conf,因为每个以 .conf 结尾的文件都被视为站点配置文件。

    我将其更改为 sitename.redirects,现在它可以正常工作了

    【讨论】:

      猜你喜欢
      • 2011-05-10
      • 2016-01-25
      • 2017-09-10
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      相关资源
      最近更新 更多