configure-nginx
关于
This skill configures Nginx as a production-ready web server and reverse proxy, handling static file serving, SSL/TLS termination with Let's Encrypt, and load balancing. It's designed for proxying to backend services like Node.js or Python apps while hardening endpoints with security headers and rate limiting. Use it when you need a robust, secure gateway for your web applications.
快速安装
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-nginx在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Configure Nginx
Set up Nginx as web server + reverse proxy w/ SSL termination + security hardening.
Use When
- Serving static files (HTML, CSS, JS) in prod
- Reverse proxying to backend services (Node.js, Python, Go, R/Shiny)
- Terminating SSL/TLS w/ Let's Encrypt certs
- Load balancing across multi backend instances
- Adding rate limiting + security headers
In
- Required: Deployment target (Docker container or bare metal)
- Required: Backend service(s) to proxy (host:port)
- Optional: Domain name for SSL
- Optional: Static file dir
Do
Step 1: Basic Reverse Proxy
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 service:
services:
nginx:
image: nginx:1.27-alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- app
→ Reqs to port 80 forwarded to app service.
Step 2: Static File Serving
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";
}
}
Step 3: SSL/TLS w/ Let's Encrypt
Using certbot w/ webroot method:
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 w/ 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:
Initial cert:
docker compose run --rm certbot certonly \
--webroot -w /var/www/certbot \
-d example.com --email [email protected] --agree-tos
→ HTTPS works w/ valid Let's Encrypt cert.
If err: Check DNS points to server. Valid. port 80 open for ACME challenges.
Step 4: Security Headers
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;
}
Step 5: Rate Limiting
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;
}
}
}
Step 6: Load Balancing
upstream app {
least_conn;
server app1:3000;
server app2:3000;
server app3:3000 backup;
}
| Method | Directive | Behavior |
|---|---|---|
| Round robin | (default) | Equal distribution |
| Least connections | least_conn | Routes to least busy |
| IP hash | ip_hash | Sticky sessions |
| Weighted | server app:3000 weight=3 | Proportional |
Step 7: Test Configuration
# 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 reports syntax OK. Headers include security headers.
Check
-
nginx -treports config valid - HTTP redirects to HTTPS (if SSL enabled)
- Backend service reachable through proxy
- Security headers in res
- Rate limiting triggers on excessive reqs
- SSL Labs test → A+ rating (if public)
Traps
- Missing
proxy_set_header Host: Backend gets wrong host header → breaks virtual hosts + redirects. locationorder matters: Nginx uses most specific match. Exact (=) > prefix (^~) > regex (~) > general prefix.- SSL cert renewal: Set up cron/timer →
certbot renew+ reload Nginx. - Large req bodies: Default
client_max_body_size= 1MB. Increase for file uploads:client_max_body_size 50m;. - WebSocket proxying: Requires additional headers. See
configure-reverse-proxyfor pattern.
→
configure-reverse-proxy- multi-tool proxy patterns inc WebSocket + Traefiksetup-compose-stack- compose stack inc Nginxdeploy-searxng- uses Nginx as frontend for SearXNGconfigure-ingress-networking- K8s ingress (NGINX Ingress Controller)
GitHub 仓库
相关推荐技能
qmd
开发这是一个本地搜索和索引的CLI工具,支持BM25、向量搜索和重排序功能。开发者可以用它快速索引本地文件(如Markdown文档)并进行混合搜索,特别适合代码库或文档的本地检索。它还提供MCP模式,能轻松集成到Claude开发环境中使用。
subagent-driven-development
开发该Skill用于在当前会话中执行包含独立任务的实施计划,它会为每个任务分派一个全新的子代理并在任务间进行代码审查。这种"全新子代理+任务间审查"的模式既能保障代码质量,又能实现快速迭代。适合需要在当前会话中连续执行独立任务,并希望在每个任务后都有质量把关的开发场景。
mcporter
开发mcporter Skill 让开发者能在Claude中直接管理和调用MCP服务器。它支持列出可用服务器、调用工具、处理OAuth认证以及管理服务器守护进程。开发者可以通过命令行式交互快速执行`mcporter list`查看服务器,或使用`mcporter call`直接调用工具,简化了MCP工作流程。
adk-deployment-specialist
开发这是一个用于部署和编排Google Vertex AI ADK智能体的Claude Skill,专为构建生产级多智能体系统而设计。它支持通过A2A协议进行智能体通信,提供代码执行沙箱和记忆库功能,并能处理智能体发现与任务提交。当开发者需要部署ADK智能体或编排多智能体协作时,可使用此Skill来简化Vertex AI Agent Engine的部署流程。
