V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
dunhanson
V2EX  ›  NGINX

nginx 限流失败的奇怪问题

  •  
  •   dunhanson · Nov 25, 2024 · 2533 views
    This topic created in 529 days ago, the information mentioned may be changed or developed.

    问题描述

    ~/info 限流失败

    ~info 和~/info 都能匹配到值,$limit_key_pc_page_info 的值输出 page_info

    为什么加/符号会影响限流?$limit_key_pc_page_info 里面有值

    1 、nginx 配置

    # 变量-URI
    map $uri $limit_key_pc_page_info {
    	~/info "page_info";
    	#~info "page_info";
    	default "";
    }
    limit_req_zone $limit_key_pc_page_info zone=limit_zone_pc_page_info:10m rate=1r/s;
    
    server {
    	listen 80;
    	server_name www.dunhanson.com;
    	charset utf-8;
    
    	location / {
    		# 限流
    		limit_req zone=limit_zone_pc_page_info nodelay;
    		proxy_pass http://www_dunhanson_com;
    	}
    }
    
    server {
    	listen 80;
    	server_name test.dunhanson.com;
    	charset utf-8;
    
    	location / {
    		default_type text/plain;
    		return 200 "$uri $limit_key_pc_page_info";
    	}
    }
    

    2 、测试效果

    curl http://test.dunhanson.com/info-558860051.html
    

    输出: /info-558860051.html page_info

    4 replies    2024-12-29 03:21:08 +08:00
    dunhanson
        1
    dunhanson  
    OP
       Nov 25, 2024
    有没有人遇到过?
    wswch4444
        2
    wswch4444  
       Nov 25, 2024
    正在研究 nginx 源码,等我研究出来,来回复😄
    dunhanson
        3
    dunhanson  
    OP
       Nov 25, 2024
    @wswch4444 源码,厉害了
    Hanada
        4
    Hanada  
       Dec 29, 2024
    配置上没看出啥问题,你是怎么测试出~/info 失败的(另外建议改成~^/info ,会更精确点)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3231 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 14:18 · PVG 22:18 · LAX 07:18 · JFK 10:18
    ♥ Do have faith in what you're doing.