Skip to Content
Go Realm v1 is released 🎉
DevOpsNginxমডিউল ২: Core Configuration

মডিউল ২: Core Configuration

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

শেখার লক্ষ্য

বুঝবেএক লাইনে
Config hierarchyhttp → server → location nesting
Block scopeকোন rule কোথায় apply হয়
Key directiveslisten, server_name, root, index, try_files
Matching logicrequest কোন location-এ যায়

Configuration Hierarchy

events { } ◀── connection-level settings http { ◀── সব web traffic-এর shared config server { ◀── এক domain / virtual host listen 80; server_name example.com; location / { ◀── URL path অনুযায়ী rule ... } } }
BlockScopeদায়িত্ব
httpglobalসব site-এর shared setting
serverper-domainএকটি virtual host
locationper-pathনির্দিষ্ট URL path-এর rule

নিয়ম: ভেতরের block বাইরের block-এর setting inherit করে, দরকারে override করে।


৫টি Must-Know Directive

Directiveকাজউদাহরণ
listenকোন port-এ শুনবেlisten 443 ssl;
server_nameকোন domainserver_name api.example.com;
rootকোন folder থেকে fileroot /var/www/app/public;
indexfolder hit করলে default fileindex index.php index.html;
try_filesfile আছে কিনা দেখে fallbacktry_files $uri $uri/ /index.php?$query_string;

try_files ভাঙা — line by line

try_files $uri $uri/ /index.php?$query_string; │ │ │ │ │ └─ কিছুই না পেলে: index.php-তে পাঠাও (query সহ) │ └───────── ওই নামে folder আছে? serve করো └──────────────── ওই নামে file আছে? serve করো

এটি Laravel routing-এর প্রাণ। কারণ Laravel-এর route file system-এ থাকে না:

/users/12/edit ──▶ file নেই ──▶ try_files fallback ──▶ index.php ──▶ Laravel router

location Matching — ৪ ধরন

Syntaxধরনকখন match
location /prefix (catch-all)সব path-এর last resort
location /api/prefix/api/... দিয়ে শুরু হলে
location = /healthexactঠিক /health হলেই
location ~ \.php$regex.php দিয়ে শেষ হলে

Priority (কে আগে জেতে)

1. = exact match (সবচেয়ে strong) 2. ^~ prefix (regex থামায়) 3. ~ / ~* regex match 4. plain prefix (সবচেয়ে weak)

Request Matching — Flow

একটি request: GET https://example.com/assets/logo.png

[1] server_name দিয়ে সঠিক server block বাছো [2] path /assets/logo.png-এর best location বাছো [3] file আছে? ──── হ্যাঁ ──▶ সরাসরি serve │ না [4] fallback rule (try_files / proxy) চালাও

Static বনাম Dynamic — Decision Table

RequestNginx কী করে
/css/app.cssfile থাকলে নিজে serve
/images/logo.pngfile থাকলে নিজে serve
/loginapp-এ forward
/api/usersproxy / PHP-FPM-এ পাঠায়

Minimum Server Block (মুখস্থ-যোগ্য skeleton)

server { listen 80; server_name demo.example.com; root /var/www/demo/public; index index.html index.php; location / { try_files $uri $uri/ /index.php?$query_string; } }

Common Mistakes

ভুলফলাফল
root path ভুল404 / wrong file
server_name mismatchdefault block hit করে
try_files বাদLaravel route ভাঙে
location /-এ heavy rulestatic serve interfere করে

Understanding Check

  1. http, server, location-এর responsibility আলাদা করে বলো।
  2. root আর server_name এক জিনিস না কেন?
  3. try_files $uri $uri/ /index.php?$query_string;-এর প্রতিটি অংশ কী করে?
  4. location = /health আর location /-এর use case কীভাবে আলাদা?
  5. Laravel route কেন সরাসরি file path হিসেবে match হয় না?

Mini Task

hr.example.com-এর জন্য skeleton server block লেখো:

  • listen 80
  • server_name hr.example.com
  • root /var/www/hr/public
  • Laravel index.php fallback

➡️ পরের ধাপ: মডিউল ৩: Reverse Proxy