Skip to main content

Command Palette

Search for a command to run...

Nginx Rate Limit : Part 1

Updated
1 min read
Nginx Rate Limit : Part 1

Nginx မှာRequest Rate Limit လုပ်ခြင်း ကို sharing လုပ်ပေးသွားပါမယ်။

Step 1:

Nginx မှာ Global Setting နဲ့သွားပါမယ်။

$sudo vim /etc/nginx/nginx.conf

ရဲ့ http block ထဲမှာ ဒီ rate limit configuration လေးပထမဆုံးသွားထည့်ပါမည်။

limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

Identifier ဖြစ်တဲ့ $binary..ကိုသုံးပြီး client ရဲ့ IP ကို မှတ်လိုက်တာပါ။

ဒီလိုမှတ်ဖို့အတွက် Memory လိုတဲ့အတွက် 10m သက်မှတ်ပေးလိုက်ပါတယ်။ 10m က 160,000 connection လောက်ကိုမှတ်ထားနိုင်ပါတယ်။

rate=10r/s ကတော့ 1 Second မှာ request 10 ခု့ပဲ ခွင့်ပြု့မယ်လို့ပြောလိုက်တာပါ။

Step 2:

Global config နဲ့သက်မှတ်ထားတဲ့ rate limit လေးကို ပြန်ခေါ်သုံးမှာဖြစ်ပါတယ်။

ဒီအတွက်

$sudo vim /etc/nginx/conf.d/example.conf

ထဲက server block ထဲမှာ ဒီ config လေးသက်မှတ်ပေးပါမယ်။

location / {
    limit_req zone=one;
}

ဆိုပြီး ပြန်ခေါ်သုံးပါမယ်။

Config OK လား

$sudo nginx -t

နဲ့စစ်ကြည့်ပါ။

$sudo nginx -s reload

နဲ့ service reload လုပ်ပေးပါ။

Rate Limit တကယ်အလုပ်လုပ်မလုပ်သိရန် apache-bench tool လေးနဲ့စစ်ကြည့်ပါ။

$sudo apt install apache-utils -y
$ab -n 100 -c 100 -m GET https://www.example.com/

Fail State မှာ 90 ပြနေရင် အဆင်ပြေပါပြီ။

ဒါဆို Nginx မှာ rate Limit သက်မှတ်တာလေးက အဆင်ပြေသွားပါပြီ။

လာရောက်ဖတ်ရှု့ပေးသူအားလုံး ကျေးဇူးတင်ပါတယ်။

204 views

More from this blog

Infrastructure ကိုင်ပြီး အိပ်ရေးမပျက် ချင် လျှင် ဒါမျိုး Alarms လုပ် 🔥🔥🔥

High Level ရေးထားတာပါ ဒါပေမဲ့ လွယ်ပါတယ် ​ကိုယ့်မှာ AWS Infra တွေရှိတယ်ဆို တွေ့သမျှ metric တွေကို alarms တွေလုပ်ပြီး notification ယူမနေဘဲ တကယ် effective ဖြစ်တဲ့ metric တွေကိုမှ CloudWatch ရဲ့ alarm feature တွေနဲ့ ပေါင်းပြီး ပို့စေချင်ပါတယ်။ ​ဥပမာ prod...

Jan 17, 20263 min read151
Infrastructure ကိုင်ပြီး အိပ်ရေးမပျက် ချင် လျှင်  ဒါမျိုး Alarms လုပ် 🔥🔥🔥

How to connect On Premises Network and Cloud (AWS)? (Part-2)

ကိုယ့်ရဲ့ ‌data center (on-prem) network နဲ့ AWS ချိတ်ဆက်ဖို့ လိုလာပြီဆိုရင် ဘယ်လို ချိတ်ဆက်ကြမလဲ? အပိုင်း (၂) မှာ တော့ Direct connect အကြောင်းကို ဆွေးနွေး သွားမှာ ဖြစ်ပါတယ်။ အပိုင်း (၁) Site-to-site VPN အကြောင်းကို လေ့လာချင်ရင်တော့ အောက်ပါ link မှာ ...

Dec 20, 20253 min read222
How to connect On Premises Network and Cloud (AWS)? (Part-2)

How to connect On Premises Network and Cloud (AWS)? (Part-1)

ကိုယ့်ရဲ့ ‌data center (on-prem) network နဲ့ AWS ချိတ်ဆက်ဖို့ လိုလာပြီဆိုရင် ချိတ်ဆက်နိုင်တဲ့ နည်း (၂) နည်း ရှိပါတယ်။ 1. Site-to-Site VPN (Virtual Private Network) 2. Direct connect Site-to-Site VPN - On-prem network နဲ့ AWS resources တွေ ချိတ်ဆက်တဲ့...

Dec 12, 20252 min read261
How to connect On Premises Network and Cloud (AWS)? (Part-1)

Accessibility for Designer

လွန်ခဲ့တဲ့အပတ်က ရုံးက Designer တွေနဲ့ တော်ကီပွားရင်း Accessibility နဲ့ပတ်သတ်တာတွေ သူတို့ကို ရှင်းပြဖြစ်တယ်။ ကိုယ်တိုင်ကလည်း အရင်ကတည်းက ဒီ topic ကိုစိတ်ဝင်စားလို့ လေ့လာနေတာဆိုတော့ အခွင့်အရေးရရင် ရသလို sharing လုပ်ဖြစ်တယ်။ အဓိကက Accessibility နဲ့ပတ်သတ်...

Nov 21, 20253 min read67
Accessibility for Designer

VPC Endpoint

အားလုံးဘဲ မင်္ဂလာပါ။ ဒီနေ့ sharing လုပ်ပေးချင်တာကတော့ VPC Endpoint အကြောင်းဘဲဖြစ်ပါတယ်။ VPC Endpoint ဆိုတာ VPC နဲ့ AWS services တွေ ကို public Internet ကို အသုံးမပြုဘဲနဲ့ Privately connect လုပ်ပေးတာ ဖြစ်ပါတယ်။ Internet Gateway, NAT Gateway နဲ့ Public...

Nov 18, 20252 min read88
VPC Endpoint
M

Myanmar Technical Blog

108 posts

Cloud, Linux, DevOps, Docker, Security အစရှိတဲ့ နည်းပညာများ အကြောင်းကို မြန်မာလို ပြန်လည်မျှဝေပေးမယ့် Blog ပဲဖြစ်ပါတယ်ခဗျာ...