NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
rateltalk
V2EX  ›  NGINX

[Nginx] 重写地址时获取不到以 0 结尾的数字

  •  
  •   rateltalk ·
    shangdev · May 24, 2022 · 2062 views
    This topic created in 1473 days ago, the information mentioned may be changed or developed.

    location 规则如下:

    server_name baidu.cn;
    location ~ ^/f/([0-9]+) {
    	set $port_num $1;
    	rewrite ^/f/(.*) http://baidu.cn/?short=$port_num permanent;
    }
    

    访问 baidu.cn/f/88 时,$port_num 是 88. 而访问 baidu.cn/f/5000 时,$port_num 是 5 而不是 5000. 有知道是什么原因的吗、

    1 replies    2022-05-24 14:39:13 +08:00
    eason1874
        1
    eason1874  
       May 24, 2022
    这配置,我测试没问题,应该不是这里导致的异常

    另外,只是重写的话,一句 rewrite 就够了,不用 location 匹配

    rewrite ^/f/([0-9]+)$ http://baidu.cn/?short=$1 permanent;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2717 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 15:13 · PVG 23:13 · LAX 08:13 · JFK 11:13
    ♥ Do have faith in what you're doing.