Skip to Content
Go Realm v1 is released 🎉
DevOpsNginxমডিউল ৫: Operations, Security, Debugging

মডিউল ৫: Operations, Security, Debugging

সময়: ৪৫ মিনিট

শেখার লক্ষ্য

বুঝবেএক লাইনে
Safe changetest → reload, blind restart নয়
Error diagnose502, 404, 403, redirect loop
Logsকোথায় access/error log
Hardeningbasic security checklist

Safe Change Workflow

config edit nginx -t ◀── syntax ও validity check (live নয়) │ ok? ├─ না ──▶ error message পড়ো, fix করো │ হ্যাঁ systemctl reload nginx ◀── downtime ছাড়া new config apply

❗ Edit করে সরাসরি restart দিও না — আগে nginx -t


reload বনাম restart বনাম test

Commandকী করেDowntime
nginx -tconfig validate করেনেই (apply-ই করে না)
systemctl reload nginxnew config apply, worker গ্রেসফুলি বদলায়নেই
systemctl restart nginxপুরো process restartbrief interruption সম্ভব

Essential Logs

/var/log/nginx/access.log ◀── কে, কখন, কোন path, কোন status /var/log/nginx/error.log ◀── কেন fail করল (debug-এর প্রথম জায়গা)
Logকখন দেখবে
access.logকোন request এলো, status code কী
error.log502/403/upstream কেন হলো

Common Errors — Diagnosis Table

Errorমানেসম্ভাব্য কারণ
502 Bad Gatewaybackend reachable নাapp down / wrong port / FPM socket mismatch / permission
404 Not Foundresource নেইwrong root / wrong location / try_files missing
403 Forbiddenaccess denieddirectory permission / listing off / root mismatch
Redirect loopঘুরতেই থাকেNginx HTTPS redirect + app-level force + X-Forwarded-Proto missing

502 Debug — Flow

502 দেখলে: [1] backend app চলছে? ──▶ ps / systemctl status [2] সঠিক port/socket? ──▶ config বনাম app [3] error.log কী বলছে? ──▶ tail -f error.log [4] permission ঠিক? ──▶ socket/file access

Universal Debugging Sequence

1. nginx -t (config valid?) 2. error.log দেখো (Nginx কী বলছে) 3. app process চলছে? (backend alive?) 4. port/socket verify (config = reality?) 5. DNS/domain mismatch? (ঠিক block hit হচ্ছে?) 6. browser request path note (আসলে কোন URL?)

Basic Hardening Checklist

কাজকেন
default site disableunwanted exposure বন্ধ
শুধু required port openattack surface কমে
client_max_body_size setupload abuse control
sensitive file block.env/.git leak রোধ
শুধু public/ web rootsource expose রোধ
SSL renew automatecert expire রোধ

Stack-specific Caution

Stackসাবধানউপসর্গ
Laravelpublic/-ই web root; .env কখনো serve নয়secret leak
Gosystemd service stable কিনাbackend crash → 502
Next.jsbuild version + process manager দিয়ে চালানোmanual start fragile → proxy broken

Understanding Check

  1. nginx -t production workflow-তে mandatory কেন?
  2. reload আর restart কবে use করবে?
  3. 502 দেখলে প্রথম ৩টি জিনিস কী check করবে?
  4. Laravel-এ .env exposure কেন বড় risk?
  5. Nginx issue আর upstream issue আলাদা করতে কী evidence খুঁজবে?

Final Practice Scenario

api.example.com হঠাৎ 502 Bad Gateway দিচ্ছে। step-by-step লেখো:

  1. কোন command দেবে
  2. কোন log দেখবে
  3. config-এর কোন line check করবে
  4. Go app-এর কোন port/process verify করবে
  5. fix-এর পরে কীভাবে safe reload করবে

কোর্স-পরবর্তী Practice Plan

[1] Laravel app ──▶ PHP-FPM + Nginx [2] Go API ──▶ systemd + Nginx reverse proxy [3] Next.js app ──▶ Nginx reverse proxy + HTTPS

এই ৩টি নিজে deploy করলে তোমার Nginx confidence practical level-এ চলে যাবে।

➡️ পরের ধাপ: Production Config Review