Redirect 如何使用nginx将数百个主机名重定向到其他主机名

Redirect 如何使用nginx将数百个主机名重定向到其他主机名,redirect,nginx,Redirect,Nginx,我有一个系统,其中许多(~20k)子域使用nginx的默认_服务器,该服务器将工作传递给应用程序 我还有许多(~100)个主机名需要重定向到正确的主机名,每个主机名都不同,然后重定向到默认的_服务器 one.example.com -> eleven.example.com two.example.com -> twelve.domain.com three.example.com -> wibble.example.com blah.domain.com -> fift

我有一个系统,其中许多(~20k)子域使用nginx的默认_服务器,该服务器将工作传递给应用程序

我还有许多(~100)个主机名需要重定向到正确的主机名,每个主机名都不同,然后重定向到默认的_服务器

one.example.com -> eleven.example.com
two.example.com -> twelve.domain.com
three.example.com -> wibble.example.com
blah.domain.com -> fifteen.example.com
重定向是任意的(没有模式)

我宁愿使用nginx可以检查重定向的某种映射文件,而不是在需要或更新新重定向时更新nginx配置以添加新的服务器块

遗憾的是,在搜索了相当一段时间后,我没有找到任何类似的例子,我发现的所有例子都为每个重定向主机使用一个新的服务器块,或者使用正则表达式。我更希望能够动态更新nginx可以引用的映射文件或数据库


我目前最好的选择是更新后台应用程序以应用重定向。

我以前确实找到了地图,但不清楚它是否可以以这种方式使用,并且没有一个示例显示它。说这很容易

这就是我所拥有的似乎有效的东西

map $host $redirect_host {
  hostnames;

  one.david.org     eleven.david.org;
  two.david.org     twelve.steve.org;
  three.steve.org   thirteen.david.org;
  four.steve.org    fourteen.steve.org;

}

server {
  ...
   if ($redirect_host) {
     return 301 $scheme://$redirect_host$request_uri;
   }
  ...
}

遗憾的是,此解决方案需要重新启动nginx,但这并不是什么大问题。

这听起来像是您要寻找的。@ColeTierney,必须提到的是,地图更改后仍需要重新加载nginx。