NGINX 配置速查表
NGINX 配置指令与运维操作:server 块、反向代理请求头、WebSocket、TLS、缓存、响应压缩与速率限制。
工作原理
NGINX resolves `server { listen; server_name; }` first, then picks the most specific `location` block, forwarding or serving static files; always validate with `nginx -t` before `reload`.
生存指南
最先需要掌握的少数几个命令。
40 条命令
CLI Check, Reload & Logs
Validate syntax, reload without dropping connections, and inspect runtime config.
- 基础必备
Test all included nginx configuration files for syntax and path errors
nginx -t适用场景
Never reload NGINX without testing first; broken config aborts reload safely only if checked.
命令解析
- -t
- Parse config and test validity without applying
示例
sudo nginx -t运行结果
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Server Blocks, Locations & Static Files
Understand location matching precedence, SPA fallbacks, and clean redirects.
Reverse Proxy, Upstreams & WebSockets
Forward client IPs, HTTP/1.1 keepalives, WebSocket upgrades, and timeouts.
TLS, Security Headers & Rate Limits
Enforce HTTPS, TLS 1.2/1.3, security headers, and per-IP rate/size caps.
Compression, Caching & Tuning
Enable gzip, cache-control headers, worker limits, and proxy microcaching.