← Foundations Course

ENGINEERING BRIDGE · 28

Linux / Nginx:Production Request 怎麼走到你的 App Process

在傳統 server 架構中,Linux 主機上可能同時跑 app process、Nginx、systemd。Nginx 常 listen 公開 80/443,再 reverse proxy 到 localhost 上的 app port。

Learning outcomes

1. Production Host

Linux VM
├─ nginx
│  listens :443
└─ node app
   listens 127.0.0.1:3000

Public traffic 不一定直接打 Node process。

2. Reverse Proxy

Internet
  ↓ HTTPS :443
Nginx
  ↓ HTTP localhost:3000
Node app
  ↓
response

Nginx 可處理 TLS、static files、routing、headers,再把 request 轉發給 app。

3. systemd Service

systemctl status course-api
systemctl restart course-api

Service manager 負責 process lifecycle,不是 application framework。

4. Logs

journalctl
  -u course-api
  --since today

如果 app crash/restart,journal 是重要 evidence。

5. Listener

ss -lntp

curl -i   http://127.0.0.1:3000/health

先驗 local app listener,再驗 Nginx,再驗外部 DNS/TLS。

Project checkpoint:Traditional Server Request Path

DNS
→ Linux public IP
→ Nginx :443
→ reverse proxy
→ Node :3000
→ Course API
→ DB

Debug evidence:Nginx 502

502 常意味 proxy upstream failure。先 curl localhost app port;若 local 也失敗,查 app process/listener;若 local 正常,再查 Nginx upstream config。

Knowledge check

  1. Nginx 和 Node app 是同一 process 嗎?
  2. reverse proxy 做什麼?
  3. 502 時第一個 local evidence?
  4. 畫出 public HTTPS 到 localhost app 的路徑。