🌐 Nginx Config Quick Reference
📐 工作原理与说明
按分类聚合条目:遍历条目列表,首次出现的分类记入有序数组并把计数置 1,后续同分类累加;柱状图以分类名为横轴、条目数为数据(图高 300),明细表逐行输出序号、分类名、该分类条目数与该分类前 2 条代表命令(以「 / 」连接)。分类名在英文态下按内置映射表替换为英文(Nginx 指令)
Nginx 配置与运维速查。
- 层级:main → events → http → server → location,指令按层级继承。
- 常用指令:listen、server_name、root、index、location、try_files、proxy_pass、rewrite。
- 反代:proxy_pass 配合 proxy_set_header 传递 Host、X-Real-IP 与 X-Forwarded-For。
- 调优:worker_processes、keepalive_timeout、gzip 压缩、缓存与限流配置。
Browse an Nginx cheat sheet in your browser — common directives and config patterns.
限流等指令有上下文限制:zone 定义通常放 http,引用指令放 http/server/location。复制整段最小示例后,先运行 nginx -t 校验再 reload。
📚 深度解析:Nginx 配置速查
💡 常见使用场景
- 反向代理/负载均衡/重写规则。
- 配置反向代理时查指令:确认 proxy_pass 结尾带不带斜杠、以及是否需要透传 Host 与真实 IP 头。
反代
`location /api { proxy_pass http://backend; }` 转发。
❓ 常见问题(FAQ)
- reload 与 restart?
- `nginx -s reload` 平滑重载不中断。
- 为什么改了配置没生效?
- 依次排查:是否执行了 nginx -t 检查语法并 reload(而非只改文件);配置文件是否被主配置 include 到;是否有多条 server 匹配而命中了默认的那条(用 server_name 与 default_server 确认);以及浏览器或 CDN 是否还缓存着旧响应。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Contexts | main, events, http, server and location nesting | nginx documentation |
| Load balancing | round-robin, least_conn and ip_hash strategies | nginx documentation |
| Caching | proxy_cache honors Cache-Control and expiry settings | nginx documentation |
⚠️ 使用说明与注意事项
- 本工具纯前端运行,数据不会上传到服务器
- 建议在主流浏览器(Chrome/Safari/Firefox/Edge)中使用
- 计算结果仅供参考,请以实际应用场景为准