Nginx入口重定向映射

时间:2020-09-15 07:28:21

标签: nginx kubernetes nginx-ingress

我一直在尝试在kubernetes中配置nginx入口以通过MAP指令重定向查询字符串匹配,但是我发现自己迷路了。 我需要执行类似的操作,但要使用入口注释。

https://azimut7.com/blog/nginx-redirect-map

我在configMap中为nginx入口添加了以下内容。

 map $arg_tag $tag_new_destination {
      'cool'    /something;
      '6.0.1'    /tags/601;
      'alfa'    /newone;
    }
  map-hash-bucket-size: "256"

但是当我尝试在入口规则的配置代码段中添加以下内容时,它给了我错误,因为该位置是一个&符位置,并且根据nginx文档,这种位置无法嵌套(因为在nginx中进行了解析)配置,这将成为服务的/位置(或您在入口路径中选择的位置)的一部分:

location /tags {
    error_page 420 = @tags_redirects;


if ( $args ~ "tag=" ) { return 420; }
try_files $uri $uri/ /index.php?$query_string;
}
 

location @tags_redirects {
    if ($tag_new_destination) {
      return 301 $tag_new_destination;
    }
}

0 个答案:

没有答案
相关问题