ar
تثبيت وتهيئة Nginx على VPS
Nginx هو خادم ويب عالي الأداء يُستخدم لاستضافة الملايين من المواقع حول العالم. يمتاز بكفاءته الاستثنائية في التعامل مع الطلبات المتزامنة واستهلاكه المنخفض للذاكرة. سيرشدك هذا الدليل عبر عملية التثبيت والتهيئة الكاملة على خادم VPS الخارجي الخاص بك.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
تثبيت Nginx وبدء تشغيله
تثبيت Nginx على Ubuntu/Debian بسيط ومباشر. نفّذ الأوامر التالية:
apt update
apt install -y nginx
بعد التثبيت، فعّله ليبدأ تلقائيًا مع تشغيل النظام:
systemctl enable nginx
systemctl start nginx
تحقق من أنه يعمل بشكل صحيح:
systemctl status nginx
افتح المنافذ في جدار الحماية:
ufw allow 'Nginx Full'
الآن يمكنك زيارة عنوان IP الخادم في المتصفح لترى صفحة ترحيب Nginx الافتراضية.
إنشاء Virtual Host للموقع
Virtual Host يُتيح استضافة أكثر من موقع على نفس الخادم. أنشئ ملف إعداد لموقعك:
nano /etc/nginx/sites-available/mysite.com
أضف المحتوى التالي مع استبدال mysite.com بنطاقك الفعلي:
server {
listen 80;
listen [::]:80;
server_name mysite.com www.mysite.com;
root /var/www/mysite.com;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
}
أنشئ مجلد الموقع وفعّل الإعداد:
mkdir -p /var/www/mysite.com
ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
تثبيت شهادة SSL مجانية مع Let's Encrypt
HTTPS أصبح معيارًا إلزاميًا لأي موقع. Let's Encrypt توفر شهادات مجانية وموثوقة:
apt install -y certbot python3-certbot-nginx
احصل على الشهادة وطبّقها تلقائيًا:
certbot --nginx -d mysite.com -d www.mysite.com
اتبع التعليمات وأدخل بريدك الإلكتروني. سيُعدّ Certbot الشهادة وتجديدها تلقائيًا كل 90 يومًا.
تحقق من إعداد التجديد التلقائي:
certbot renew --dry-run
لعرض الشهادات المثبتة:
certbot certificates
تحسين أداء Nginx وإعدادات الأمان
أضف هذه الإعدادات في /etc/nginx/nginx.conf لتحسين الأداء:
worker_processes auto;
worker_connections 1024;
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/json application/javascript;
لتعزيز الأمان، أضف رؤوس HTTP في ملف server block:
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
أخفِ إصدار Nginx لتقليل المعلومات المتاحة للمهاجمين:
server_tokens off;
اختبر الإعداد ثم أعد التشغيل:
nginx -t && systemctl reload nginx
Related Services
Why Anubiz Host
100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.