Community Tutorials Debian كيفية تثبيت Nginx على ديبيان 12
كيفية تثبيت Nginx على ديبيان 12
DEBIAN

كيفية تثبيت Nginx على ديبيان 12

SKYLINE Knowledge Base
Photo by Sigmund on Unsplash

دليل عملي خطوة بخطوة لـ كيفية تثبيت Nginx على ديبيان 12. أوامر مختبرة في الإنتاج، متطلبات مسبقة، تحقق نهائي وروابط لمواضيع ذات صلة.

Nginx هو الوكيل العكسي/خادم الملفات الثابتة الافتراضي في معظم مكدسات Linux الحديثة. هذا الدليل يثبت حزمة Nginx الرسمية على Debian 12 (وليس الإصدار الأقدم من مستودع التوزيعة)، يخدم موقعًا أساسيًا، ينهي TLS عبر Let's Encrypt، ويضيف ترويسات الأمان الأساسية.

المتطلبات المسبقة

  • Debian 12 مع sudo.
  • سجل DNS A/AAAA يشير إلى الخادم.
  • اتصال خارجي TCP/443 + 80.

الخطوة 1: إضافة مستودع Nginx الرسمي

sudo apt update
sudo apt install -y curl gnupg2 ca-certificates lsb-release debian-archive-keyring

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
  | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian $(lsb_release -cs) nginx" \
  | sudo tee /etc/apt/sources.list.d/nginx.list

sudo apt update
sudo apt install -y nginx
sudo systemctl enable --now nginx

الخطوة 2: فتح جدار الحماية

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

الخطوة 3: خدمة موقع ثابت

sudo mkdir -p /var/www/example.sa
echo '<h1>Hello from SKYLINE</h1>' | sudo tee /var/www/example.sa/index.html
sudo chown -R www-data:www-data /var/www/example.sa

/etc/nginx/conf.d/example.sa.conf:

server {
    listen 80;
    server_name example.sa www.example.sa;
    root  /var/www/example.sa;
    index index.html;
    location / { try_files $uri $uri/ =404; }
}
sudo nginx -t && sudo systemctl reload nginx
curl -fI http://example.sa/

الخطوة 4: TLS مع Let's Encrypt

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.sa -d www.example.sa \
  --agree-tos --redirect -m ops@example.sa --no-eff-email

الخطوة 5: ترويسات الأمان الأساسية

/etc/nginx/conf.d/headers.conf:

add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
add_header X-Content-Type-Options    "nosniff" always;
add_header Referrer-Policy           "strict-origin-when-cross-origin" always;
add_header X-Frame-Options           "SAMEORIGIN" always;

الخطوة 6: كتلة وكيل عكسي بسيطة

location / {
    proxy_pass         http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header   Host              $host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

التحقق

sudo nginx -t
curl -fI https://example.sa/

الخاتمة

Nginx الرسمي + Certbot هو أسهل طريق لخادم HTTPS موثوق على Debian.

الخطوات التالية

SKYLINE Engineering

@skyline

The engineering team at SKYLINE Industrial Solutions. We publish field-tested guides drawn from real KSA and GCC deployments.

See author profile
SKYLINE engineering services

Need this implemented for you?

Reading is free — building it right takes a team. SKYLINE engineers ship Debian for Aramco vendors, banks, hospitals and government agencies across Saudi Arabia. Talk to us before you start.

Aramco Approved Contractor ISO 9001 · ISO 27001 SAMA CSF aligned NCA ECC ready 247+ KSA clients

Comments

0 total · 0 threads
Be the first to leave a comment.