V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
s609926202
V2EX  ›  NGINX

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

  •  
  •   s609926202 ·
    shangdev · 2022-05-24 11:27:30 +08:00 · 1193 次点击
    这是一个创建于 693 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2022-05-24 14:39:13 +08:00
    eason1874
        1
    eason1874  
       2022-05-24 14:39:13 +08:00
    这配置,我测试没问题,应该不是这里导致的异常

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

    rewrite ^/f/([0-9]+)$ http://baidu.cn/?short=$1 permanent;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5963 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:07 · PVG 14:07 · LAX 23:07 · JFK 02:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.