包含文件中的Nginx映射模块正则表达式不起作用

问题描述 投票:0回答:1

我正在尝试将某些URL重定向到其他文档路径。我的配置文件如下

###### /etc/nginx/conf.d/site.conf
    map_hash_max_size 2048;
    map_hash_bucket_size 128;
    map $uri $new {
            include list_4;
    }
    resolver  127.0.0.1;
    server {
            listen         81;
            server_name abcexample.com;
            access_log /var/log/nginx/abcexample-access.log main;
            error_log  /var/log/nginx/abcexample-error.log;
            location / {
                    if ($new) {
                      rewrite ^ $new redirect;
                    }
                  proxy_pass http://127.0.0.1:8000;
            }
     }
########### / etc / nginx / list_4
/abc/1.html /abc/hello;
/max/1.html /max/;
~^/xyz/(?<abc>.*)$ /xyz/123;
~^/kkkk/abcdef(?<abc>.*)$ /tttt/bbbbb/jjjj$abc;
~^/kaka/(?<abc>.*)$ /tata/$abc;

注意:第1,2和3行重定向工作正常。但是第4行和第5行不起作用。

root@Hell1:~# curl -I abcexample.com/kkkk/abcef111.html 
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Tue, 04 Apr 2017 07:08:47 GMT
Content-Type: text/html
Content-Length: 154
Location: http://abcdexample.com/tttt/bbbbb/jjjj$abc
Connection: keep-alive

我的问题是:我必须在list_4文件中进行哪些更改才能获得结果,如下所示

Location: http://abcdexample.com/news/bbbbb/jjjj111.html 
regex nginx url-rewriting url-mapping
1个回答
0
投票

仅从版本1.11.0起才可以使用变量和文本的组合。

结果值可以包含文本,变量(0.9.0)及其组合(1.11.0)。

http://nginx.org/en/docs/http/ngx_http_map_module.html#map

nginx 1.11.0的更改--- 2016年5月24日

*)功能:“ map”指令支持将多个变量组合作为结果值。

http://nginx.org/en/CHANGES

© www.soinside.com 2019 - 2024. All rights reserved.