安裝步驟
- 下載 Nginx Windows 版(官網),解壓至無中文路徑目錄(如 `D:\nginx`)。
- 修改 `conf/nginx.conf`:
- `worker_processes auto;`
- `events { worker_connections 1024; }`
- `http { include mime.types; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html; } } }` - 啟動:雙擊 `nginx.exe` 或 CMD 執行 `start nginx`。
- 驗證:瀏覽器訪問 `https://localhost` 出現 "Welcome to nginx!"。
域名測試配置
編輯 `C:\Windows\System32\drivers\etc\hosts` 添加 127.0.0.1 test.local,`nginx.conf` 新增 `server_name test.local;`,重載 `nginx -s reload`。
高併發優化建議
- 調整 `worker_processes` 為 CPU 核心數。
- 開啟 `sendfile`、`tcp_nopush`、`tcp_nodelay`。
- 使用 `ab` 或 `wrk` 壓測:`wrk -t4 -c200 -d30s https://test.local/`。
參考資源