configure-nginx
について
このスキルは、Nginxを本番環境対応のWebサーバーおよびリバースプロキシとして設定し、静的ファイルの提供、Let's EncryptによるSSL/TLS終端、アップストリームサービスへの負荷分散を扱います。Node.jsやPythonアプリなどのバックエンドへのプロキシ、セキュリティヘッダーによるエンドポイントの強化、レート制限の実装に使用されます。開発者は、安全で高性能なゲートウェイを必要とするWebアプリケーションをデプロイする際にこれを利用すべきです。
クイックインストール
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 and reverse proxy with SSL termination, security hardening.
When Use
- Serving static files (HTML, CSS, JS) in production
- Reverse proxying to backend services (Node.js, Python, Go, R/Shiny)
- Terminating SSL/TLS with Let's Encrypt certificates
- Load balancing across multiple backend instances
- Adding rate limiting, security headers
Inputs
- Required: Deployment target (Docker container or bare metal)
- Required: Backend service(s) to proxy (host:port)
- Optional: Domain name for SSL
- Optional: Static file directory
Steps
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
Got: Requests 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 with Let's Encrypt
Using certbot with 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 with 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 certificate:
docker compose run --rm certbot certonly \
--webroot -w /var/www/certbot \
-d example.com --email [email protected] --agree-tos
Got: HTTPS works with valid Let's Encrypt certificate.
If fail: Check DNS points to server. Verify 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
Got: nginx -t reports syntax OK. Headers include security headers.
Checks
-
nginx -treports configuration valid - HTTP redirects to HTTPS (if SSL enabled)
- Backend service reachable through proxy
- Security headers present in response
- Rate limiting triggers on excessive requests
- SSL Labs test gives A+ rating (if public)
Pitfalls
- Missing
proxy_set_header Host: Backend receives wrong host header, breaking virtual hosts and redirects. locationorder matters: Nginx uses most specific match. Exact (=) > prefix (^~) > regex (~) > general prefix.- SSL certificate renewal: Set up cron or timer to run
certbot renew, reload Nginx. - Large request bodies: Default
client_max_body_sizeis 1MB. Increase for file uploads:client_max_body_size 50m;. - WebSocket proxying: Requires additional headers. See
configure-reverse-proxyfor pattern.
See Also
configure-reverse-proxy- multi-tool proxy patterns including WebSocket and Traefiksetup-compose-stack- compose stack that includes Nginxdeploy-searxng- uses Nginx as frontend for SearXNGconfigure-ingress-networking- Kubernetes ingress (NGINX Ingress Controller)
GitHub リポジトリ
関連スキル
qmd
開発qmdは、BM25、ベクトル埋め込み、およびリランキングを組み合わせたハイブリッド検索を用いて、ローカルファイルのインデックス作成と検索を可能にするローカル検索・インデックス作成CLIツールです。コマンドラインでの使用と、Claudeとの統合のためのMCP(Model Context Protocol)モードの両方をサポートしています。このツールは埋め込みにOllamaを使用し、インデックスをローカルに保存するため、ターミナルから直接ドキュメントやコードベースを検索するのに最適です。
subagent-driven-development
開発このスキルは、各独立したタスクに対して新規のサブエージェントを起動し、タスク間でコードレビューを実施しながら実装計画を実行します。レビュープロセスを通じて品質基準を維持しつつ、迅速な反復を可能にします。同一セッション内で主に独立したタスクに取り組む際に本スキルをご利用いただくことで、組み込まれた品質チェックを伴う継続的な進捗を確保できます。
mcporter
開発mcporterスキルは、開発者がClaudeから直接Model Context Protocol(MCP)サーバーを管理および呼び出せるようにします。このスキルは、利用可能なサーバーの一覧表示、引数を指定したツールの呼び出し、認証およびデーモンのライフサイクル管理を行うコマンドを提供します。開発ワークフローにおいてMCPサーバーの機能を統合およびテストする際に、このスキルをご利用ください。
adk-deployment-specialist
開発このスキルは、A2Aプロトコルを使用してVertex AI ADKエージェントをデプロイおよびオーケストレーションし、AgentCardの発見、タスク送信、およびコード実行サンドボックスやメモリバンクなどのサポートツールを管理します。Python、Java、またはGoで、順次、並列、またはループのオーケストレーションパターンを用いたマルチエージェントシステムの構築を可能にします。Google Cloud上でADKエージェントのデプロイやエージェントワークフローのオーケストレーションを求められた際にご利用ください。
