정보
이 스킬은 프로덕션 환경에서 Nginx를 웹 서버 및 리버스 프록시로 구성합니다. 정적 파일 제공, Let's Encrypt를 통한 SSL/TLS 종료, 로드 밸런싱, Node.js나 Python 같은 백엔드 서비스로의 프록시 기능을 활성화합니다. 개발자들은 이를 활용해 애플리케이션에 속도 제한, 보안 헤더, 안전한 엔드포인트를 추가할 수 있습니다.
빠른 설치
Claude Code
추천npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/configure-nginxClaude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요
문서
配置 Nginx
设置 Nginx 作为具有 SSL 终止和安全加固的 Web 服务器和反向代理。
适用场景
- 在生产环境中提供静态文件(HTML、CSS、JS)服务
- 反向代理到后端服务(Node.js、Python、Go、R/Shiny)
- 使用 Let's Encrypt 证书终止 SSL/TLS
- 跨多个后端实例负载均衡
- 添加速率限制和安全头
输入
- 必需:部署目标(Docker 容器或裸金属服务器)
- 必需:需要代理的后端服务(host:port)
- 可选:用于 SSL 的域名
- 可选:静态文件目录
步骤
第 1 步:基本反向代理
nginx.conf:
events {
worker_connections 1024;
}
http {
upstream app {
server app:3000;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Docker Compose 服务:
services:
nginx:
image: nginx:1.27-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- app
预期结果: 端口 80 的请求被转发到 app 服务。
第 2 步:静态文件服务
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
expires 6M;
add_header Cache-Control "public";
}
}
第 3 步:使用 Let's Encrypt 的 SSL/TLS
使用 certbot 的 webroot 方式:
server {
listen 80;
server_name example.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Docker Compose 配合 certbot:
services:
nginx:
image: nginx:1.27-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- certbot-webroot:/var/www/certbot:ro
- certbot-certs:/etc/letsencrypt:ro
certbot:
image: certbot/certbot
volumes:
- certbot-webroot:/var/www/certbot
- certbot-certs:/etc/letsencrypt
volumes:
certbot-webroot:
certbot-certs:
初始证书申请:
docker compose run --rm certbot certonly \
--webroot -w /var/www/certbot \
-d example.com --email [email protected] --agree-tos
预期结果: HTTPS 使用有效的 Let's Encrypt 证书正常工作。
失败处理: 检查 DNS 是否指向服务器。验证端口 80 是否对 ACME 挑战开放。
第 4 步:安全头
server {
# ... SSL config above ...
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';" always;
# Hide Nginx version
server_tokens off;
}
第 5 步:速率限制
http {
# Define rate limit zones
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://app;
}
location /login {
limit_req zone=login burst=5;
proxy_pass http://app;
}
}
}
第 6 步:负载均衡
upstream app {
least_conn;
server app1:3000;
server app2:3000;
server app3:3000 backup;
}
| 方法 | 指令 | 行为 |
|---|---|---|
| 轮询 | (默认) | 平均分配 |
| 最少连接 | least_conn | 路由到最空闲的 |
| IP 哈希 | ip_hash | 粘性会话 |
| 加权 | server app:3000 weight=3 | 按比例分配 |
第 7 步:测试配置
# Test config syntax
docker compose exec nginx nginx -t
# Reload without downtime
docker compose exec nginx nginx -s reload
# Check response headers
curl -I https://example.com
预期结果: nginx -t 报告语法正确。头部包含安全头。
验证清单
-
nginx -t报告配置有效 - HTTP 重定向到 HTTPS(如启用 SSL)
- 后端服务可通过代理访问
- 响应中存在安全头
- 速率限制在请求过多时触发
- SSL Labs 测试获得 A+ 评级(如公开访问)
常见问题
- 缺少
proxy_set_header Host:后端接收到错误的主机头,导致虚拟主机和重定向失效 location顺序很重要:Nginx 使用最具体的匹配。精确匹配(=)> 前缀匹配(^~)> 正则匹配(~)> 一般前缀- SSL 证书续期:设置 cron 或 timer 运行
certbot renew并重载 Nginx - 大请求体:默认
client_max_body_size为 1MB。对文件上传增大:client_max_body_size 50m; - WebSocket 代理:需要额外头。参见
configure-reverse-proxy获取模式
相关技能
configure-reverse-proxy— 包括 WebSocket 和 Traefik 的多工具代理模式setup-compose-stack— 包含 Nginx 的 compose 栈deploy-searxng— 使用 Nginx 作为 SearXNG 的前端configure-ingress-networking— Kubernetes 入口(NGINX Ingress Controller)
GitHub 저장소
Frequently asked questions
What is the configure-nginx skill?
configure-nginx is a Claude Skill by pjt222. Skills package instructions and resources that Claude loads on demand, so Claude can perform configure-nginx-related tasks without extra prompting.
How do I install configure-nginx?
Use the install commands on this page: add configure-nginx to Claude Code as a plugin, or clone its repository into your skills directory, then restart Claude so it picks up the skill.
What category does configure-nginx belong to?
configure-nginx is in the Other category, tagged general.
Is configure-nginx free to use?
Yes. configure-nginx is listed on AIMCP and free to install. It runs inside Claude, so no separate service account is required to use the skill itself.
연관 스킬
LlamaGuard는 폭력 및 혐오 발언 등 6가지 안전 범주에서 LLM 입력과 출력을 조정하기 위한 Meta의 70-80억 파라미터 모델입니다. 94-95% 정확도를 제공하며 vLLM, Hugging Face 또는 Amazon SageMaker를 사용해 배포할 수 있습니다. 이 기술을 사용하여 AI 애플리케이션에 콘텐츠 필터링 및 안전 가드레일을 손쉽게 통합하세요.
이 Claude Skill은 리소스 적정화, 태깅 전략, 지출 분석을 통해 개발자들이 클라우드 비용을 최적화할 수 있도록 지원합니다. AWS, Azure, GCP에서 클라우드 비용을 절감하고 비용 거버넌스를 구현하기 위한 프레임워크를 제공합니다. 인프라 비용을 분석하거나, 리소스를 적정화하거나, 예산 제약을 충족해야 할 때 사용하세요.
이 Claude Skill은 스프레드, 오버/언더, 프로프 베트를 포함한 스포츠 베팅 시장을 분석합니다. 역사적 추이와 상황별 통계를 검토하여 가치 베트를 발견하고, 교육적 목적으로 실행 가능한 권장 사항이 담긴 구조화된 마크다운 결과를 제공합니다. 개발자는 이 기능을 스포츠 베팅 분석 도구에 활용할 수 있으며, 단순히 엔터테인먼트/교육 목적으로만 설계되었음을 유의해야 합니다.
이 스킬은 bitsandbytes를 사용하여 LLM을 8비트 또는 4비트 정밀도로 양자화하며, 최소한의 정확도 손실로 50-75%의 메모리 감소를 달성합니다. 제한된 GPU 메모리에서 더 큰 모델을 실행하거나 추론을 가속화하는 데 이상적이며, INT8, NF4, FP4와 같은 형식을 지원합니다. 이 스킬은 HuggingFace Transformers와 통합되어 QLoRA 학습 및 8비트 옵티마이저를 가능하게 합니다.
