Nginx 是一款高性能的开源 Web 服务器和反向代理服务器,以其轻量级、高并发处理能力和丰富的功能而闻名。以下是 Nginx 的主要用途和典型场景:
gzip
压缩、缓存控制(expires
头)、sendfile
零拷贝等技术优化性能。nginx
upstream backend {
server 10.0.0.1:8080 weight=3;
server 10.0.0.2:8080;
}
nginx
server {
listen 443 ssl;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
}
FastCGI
(PHP)、uWSGI
(Python)、proxy_pass
(Node.js/Java)转发动态请求到后端应用服务器。
nginx
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
}
nginx
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
ngx_http_geo_module
封禁IP。access_log
)、错误日志(error_log
),支持日志分割和分析。rewrite
规则实现伪静态或重定向。nginx
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
location
)将请求分发到不同微服务。limit_req
)、CORS 跨域等。ngx_mail_module
)。如果需要具体配置示例或问题解决方案,可以进一步说明场景!