mcpField
N
nginx-configuration

nginx-configuration

github.com/aj-geddes云与 DevOps3731.5k 次安装34 周前更新
代码仓库

关于 nginx-configuration

用于配置 Nginx Web 服务器和基础设施的技能,涵盖反向代理、负载均衡、TLS、缓存、路由及生产环境实践。

主要功能

  1. 01反向代理配置
  2. 02负载均衡
  3. 03TLS 终止
  4. 04缓存与压缩
  5. 05路由与速率限制

适用场景

  1. 01将请求转发到后端服务
  2. 02在多个后端间分配流量
  3. 03配置 HTTPS 和缓存

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill nginx-configuration

安装后在 Claude Code 中输入/nginx-configuration确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
https-server-with-load-balancing.md
nginx-configuration-script.md
nginx-monitoring-configuration.md
production-nginx-configuration.md
scripts/
validate-api.sh
templates/
api-scaffold.yaml

详细介绍

Nginx 配置

目录

概述

掌握 Nginx 配置,用于生产级 Web 服务、反向代理、负载均衡、SSL 终止、缓存和 API 网关模式,并进行高级性能调优。

适用场景

  • 配置反向代理
  • 在后端服务之间进行负载均衡
  • SSL/TLS 终止
  • 支持 HTTP/2 和 gRPC
  • 缓存和压缩
  • 速率限制和 DDoS 防护
  • URL 重写和路由
  • 实现 API 网关功能

快速开始

最小可用示例:

# /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 4096;
    use epoll;
    multi_accept on;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Logging
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    log_format upstream_time '$remote_addr - $remote_user [$time_local] '
                            '"$request" $status $body_bytes_sent '
                            '"$http_referer" "$http_user_agent" '
// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
生产环境 Nginx 配置生产环境 Nginx 配置
启用负载均衡的 HTTPS 服务启用负载均衡的 HTTPS 服务
Nginx 配置脚本Nginx 配置脚本
Nginx 监控配置Nginx 监控配置

最佳实践

✅ 应当
  • 使用 HTTP/2 提升性能
  • 使用强加密套件启用 SSL/TLS
  • 实施适当的缓存策略
  • 使用上游连接池
  • 使用 stub_status 或 prometheus 进行监控
  • 设置速率限制以防止滥用
  • 添加安全标头
  • 使用 least_conn 进行负载均衡
  • 将错误日志与访问日志分开
❌ 不要
  • 禁用 gzip 压缩
  • 使用弱 SSL 加密套件
  • 缓存经过身份验证的响应
  • 允许直接访问后端
  • 忽略上游健康检查
  • 混用 HTTP 和 HTTPS 而不进行重定向
  • 在生产环境中使用默认错误页面
  • 缓存敏感的用户数据

评论

支持 Markdown