تقوية Nginx باستخدام ترويسات الأمان
أضيفوا ترويسات أمان HTTP في Nginx للحماية من هجمات اختطاف النقرات واستكشاف نوع MIME وحقن المحتوى.
تقوية 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 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Headers as a Defense Layer
Beyond TLS and authentication, modern browsers honor security headers that instruct them how to behave. Nginx can inject these on every response with the add_header directive.
Preventing MIME Sniffing
X-Content-Type-Options: nosniff stops browsers from guessing a resource's type, blocking attacks that disguise a script as an image.
add_header X-Content-Type-Options "nosniff" always;Blocking Clickjacking
X-Frame-Options controls whether your site can be embedded in a frame. Use DENY or SAMEORIGIN to prevent clickjacking.
add_header X-Frame-Options "SAMEORIGIN" always;Strict Transport Security
HSTS forces browsers to use HTTPS for future visits. Set a long max-age once HTTPS is stable everywhere.
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;Content Security Policy
A Content-Security-Policy restricts where scripts, styles, and other resources may load from, mitigating cross-site scripting.
add_header Content-Security-Policy "default-src 'self'" always;Controlling the Referrer
Referrer-Policy limits how much referrer information leaks to other sites when users click outbound links.
add_header Referrer-Policy "strict-origin-when-cross-origin" always;Why the always Flag
Without always, Nginx adds the header only on successful responses (2xx, 3xx). The always flag ensures the header is present on error responses too.
add_header X-Frame-Options "DENY" always;Hiding the Nginx Version
By default Nginx reveals its version in the Server header and error pages. Turn this off to give attackers less information.
server_tokens off;The add_header Inheritance Trap
If a location block has its own add_header, it replaces all inherited headers from the parent. Re-declare needed headers in nested blocks.
# headers in http/server are dropped here
location /api {
add_header X-Content-Type-Options "nosniff" always;
}Grouping Security Headers
Keep all security headers in one include file and pull it into each server block for consistency.
# security_headers.conf
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# server block:
include /etc/nginx/security_headers.conf;Verifying Headers
Use curl to inspect the response headers and confirm each one is present, even on error responses.
curl -I https://example.comQuick Check
Which header tells the browser to refuse loading your site inside a frame on another domain?
Recap
You hardened Nginx with browser security headers:
nosniffblocks MIME confusionX-Frame-Optionsstops clickjacking- HSTS enforces HTTPS, CSP restricts resources
- Use
alwaysand bewareadd_headerinheritance server_tokens offhides the version
These complement TLS and authentication for defense in depth.
الأسئلة الشائعة
هل درس «تقوية Nginx باستخدام ترويسات الأمان» مجاني؟
نعم — نص درس «تقوية Nginx باستخدام ترويسات الأمان» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، انتقل إلى CoddyKit PRO. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.
ماذا ستتعلم في «تقوية Nginx باستخدام ترويسات الأمان»؟
أضيفوا ترويسات أمان HTTP في Nginx للحماية من هجمات اختطاف النقرات واستكشاف نوع MIME وحقن المحتوى. تتمرن على 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.
كم من الوقت يستغرق درس «تقوية Nginx باستخدام ترويسات الأمان»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) هذا؟
نعم. كل درس في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تأمين Nginx باستخدام SSL/TLS
- HTTP/2 وتحسين Nginx
- المصادقة الأساسية والتحكم في الوصول
- تقوية Nginx باستخدام ترويسات الأمان