nginx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNginx
Nginx
Nginx is the world's most popular web server. v1.25+ (2025) supports HTTP/3 (QUIC) natively.
Nginx是全球最受欢迎的网页服务器。2025年发布的v1.25+版本原生支持**HTTP/3 (QUIC)**协议。
When to Use
适用场景
- Reverse Proxy: Termination of SSL, load balancing to backend apps (Node/Python).
- Static Content: Serving React/Vue bundles efficiently.
- Ingress: Nginx Ingress Controller is the standard K8s ingress.
- 反向代理:终止SSL连接,为后端应用(Node/Python)实现负载均衡。
- 静态内容托管:高效分发React/Vue打包文件。
- Ingress网关:Nginx Ingress Controller是Kubernetes(K8s)的标准Ingress组件。
Quick Start
快速入门
nginx
undefinednginx
undefinednginx.conf
nginx.conf
server {
listen 443 quic reuseport;
listen 443 ssl;
http2 on;
server_name example.com;
ssl_certificate cert.pem;
ssl_certificate_key key.pem;
location / {
proxy_pass http://localhost:3000;
add_header Alt-Svc 'h3=":443"; ma=86400';
}}
undefinedserver {
listen 443 quic reuseport;
listen 443 ssl;
http2 on;
server_name example.com;
ssl_certificate cert.pem;
ssl_certificate_key key.pem;
location / {
proxy_pass http://localhost:3000;
add_header Alt-Svc 'h3=":443"; ma=86400';
}}
undefinedCore Concepts
核心概念
Worker Processes
工作进程
Event-driven architecture. Handles 10k+ connections with low RAM.
采用事件驱动架构,可在低内存占用下处理10000+并发连接。
Contexts
配置上下文
httpserverlocation包含、、三类,遵循配置继承规则。
httpserverlocationModules
模块扩展
Extend functionality (e.g., for metrics).
ngx_http_stub_status_module用于扩展功能(例如,模块可提供监控指标)。
ngx_http_stub_status_moduleBest Practices (2025)
2025年最佳实践
Do:
- Enable HTTP/3: Enable QUIC for lower latency over unreliable networks.
- Tune Buffers: Optimizing prevents disk I/O.
client_body_buffer_size - Security Headers: Always set HSTS, X-Frame-Options, etc.
Don't:
- Don't using is evil: Avoid complex logic in Nginx config. Use
ifortry_files.map
推荐做法:
- 启用HTTP/3:在不稳定网络环境下,启用QUIC协议以降低延迟。
- 调优缓冲区:优化参数可避免磁盘I/O操作。
client_body_buffer_size - 配置安全头:始终设置HSTS、X-Frame-Options等安全响应头。
不推荐做法:
- 避免使用指令:Nginx配置中应避免复杂逻辑,推荐使用
if或try_files指令替代。map