nginx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nginx

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
undefined
nginx
undefined

nginx.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';
}
}
undefined
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';
}
}
undefined

Core Concepts

核心概念

Worker Processes

工作进程

Event-driven architecture. Handles 10k+ connections with low RAM.
采用事件驱动架构,可在低内存占用下处理10000+并发连接。

Contexts

配置上下文

http
,
server
,
location
. Configuration inheritance rules.
包含
http
server
location
三类,遵循配置继承规则。

Modules

模块扩展

Extend functionality (e.g.,
ngx_http_stub_status_module
for metrics).
用于扩展功能(例如,
ngx_http_stub_status_module
模块可提供监控指标)。

Best Practices (2025)

2025年最佳实践

Do:
  • Enable HTTP/3: Enable QUIC for lower latency over unreliable networks.
  • Tune Buffers: Optimizing
    client_body_buffer_size
    prevents disk I/O.
  • Security Headers: Always set HSTS, X-Frame-Options, etc.
Don't:
  • Don't using
    if
    is evil
    : Avoid complex logic in Nginx config. Use
    try_files
    or
    map
    .
推荐做法:
  • 启用HTTP/3:在不稳定网络环境下,启用QUIC协议以降低延迟。
  • 调优缓冲区:优化
    client_body_buffer_size
    参数可避免磁盘I/O操作。
  • 配置安全头:始终设置HSTS、X-Frame-Options等安全响应头。
不推荐做法:
  • 避免使用
    if
    指令
    :Nginx配置中应避免复杂逻辑,推荐使用
    try_files
    map
    指令替代。

References

参考资料