كتل location في Nginx ومطابقة الطلبات
أتقنوا كتل location في Nginx وقواعد المطابقة التي تحدد أي إعداد سيتولى معالجة كل طلب وارد.
كتل location في Nginx ومطابقة الطلبات درس مجاني في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Location Blocks Matter
A real site serves many paths differently: static files, an API, an admin area. Location blocks let Nginx apply different rules per URL path.
Anatomy of a Location
A location block matches a request URI and contains directives for it.
location /images/ {
root /var/www;
}Prefix Matching
By default a location is a prefix match: location /blog matches /blog, /blog/post, and anything starting with it.
location /blog {
# matches /blog, /blog/, /blog/anything
}Exact Match with =
The = modifier requires an exact URI. It is fast and great for hot paths like the health endpoint or homepage.
location = /health {
return 200 'ok';
}Regex Matching
Use ~ for case-sensitive and ~* for case-insensitive regular expressions, handy for file extensions.
location ~* \.(jpg|png|gif)$ {
expires 30d;
}The Matching Priority
Nginx does not just pick the first match. Order of precedence:
=exact match wins immediately^~prefix stops regex search- regex (
~/~*) in file order - longest plain prefix as fallback
The ^~ Modifier
^~ means: if this prefix is the longest match, use it and skip regex checking. Useful to protect a static directory from regex rules.
location ^~ /static/ {
root /var/www;
}Longest Prefix Wins
Among plain prefixes, the longest match is chosen, not the first listed. /api/v2 beats /api for a request to /api/v2/users.
Combining with proxy_pass
Location blocks commonly route to backends. Different paths can proxy to different upstreams.
location /api/ {
proxy_pass http://127.0.0.1:8080;
}Nested and Named Locations
Locations can nest inside others, and named locations (@name) are jumped to internally, often for fallbacks like try_files.
location / {
try_files $uri @app;
}
location @app {
proxy_pass http://backend;
}Debugging Matches
When a request hits the wrong block, check: is there an exact or ^~ match stealing it? Is a regex matching unexpectedly? Reload and test with curl -v.
nginx -t && nginx -s reloadQuick Check
Test your location matching knowledge.
Recap
You learned Nginx location matching:
- Prefix match is the default;
=is exact - Regex uses
~and~* - Priority: exact, then
^~, then regex, then longest prefix - Longest prefix wins among plain matches
- Named locations enable fallbacks; test with
nginx -tand reload
الأسئلة الشائعة
هل درس «كتل location في Nginx ومطابقة الطلبات» مجاني؟
نعم — نص درس «كتل location في Nginx ومطابقة الطلبات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، انتقل إلى CoddyKit PRO. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.
ماذا ستتعلم في «كتل location في Nginx ومطابقة الطلبات»؟
أتقنوا كتل location في Nginx وقواعد المطابقة التي تحدد أي إعداد سيتولى معالجة كل طلب وارد. تتمرن على API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)؟
لا تُشترط خبرة سابقة. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «كتل location في Nginx ومطابقة الطلبات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) هذا؟
نعم. كل درس في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تثبيت Nginx وإعداده
- إعداد Nginx الأساسي
- تقديم المحتوى الثابت باستخدام Nginx
- كتل location في Nginx ومطابقة الطلبات