π¦ ClawHub
Nginx
by @ivangdavila
Configure Nginx for reverse proxy, load balancing, SSL termination, and high-performance static serving.
TERMINAL
clawhub install nginxπ About This Skill
name: Nginx slug: nginx version: 1.0.1 description: Configure Nginx for reverse proxy, load balancing, SSL termination, and high-performance static serving.
When to Use
User needs Nginx expertise β from basic server blocks to production configurations. Agent handles reverse proxy, SSL, caching, and performance tuning.
Quick Reference
| Topic | File |
|-------|------|
| Reverse proxy patterns | proxy.md |
| SSL/TLS configuration | ssl.md |
| Performance tuning | performance.md |
| Common configurations | examples.md |
Location Matching
= first, then ^~ prefix, then regex ~/~*, then longest prefixlocation /api matches /api, /api/, /api/anything β prefix matchlocation = /api only matches exactly /api β not /api/location ~ \.php$ is regex, case-sensitive β ~* for case-insensitive^~ stops regex search if prefix matches β use for static filesproxy_pass Trailing Slash
proxy_pass http://backend preserves location path β /api/users β /api/usersproxy_pass http://backend/ replaces location path β /api/users β /userscurl -v to see actual backend requesttry_files
try_files $uri $uri/ /index.html for SPA β checks file, then dir, then fallback=404 for error$uri/ tries directory with index β set index index.htmlproxy_pass directlyProxy Headers
proxy_set_header Host $host β backend sees original host, not proxy IPproxy_set_header X-Real-IP $remote_addr β client IP, not proxyproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for β append to chainproxy_set_header X-Forwarded-Proto $scheme β for HTTPS detectionUpstream
upstream block β upstream backend { server 127.0.0.1:3000; }proxy_pass http://backend uses upstream β load balancing includedmax_fails and fail_timeout β marks server unavailablekeepalive 32 for connection pooling β reduces connection overheadSSL/TLS
ssl_certificate is full chain β cert + intermediates, not just certssl_certificate_key is private key β keep permissions restrictedssl_protocols TLSv1.2 TLSv1.3 β disable older protocolsssl_prefer_server_ciphers on β server chooses cipher, not clientCommon Mistakes
nginx -t before nginx -s reload β test config firstroot inside location β prefer in server, override only when neededalias vs root β alias replaces location, root appends locationif β many things break inside if, avoid complex logicVariables
$uri is decoded, normalized path β /foo%20bar becomes /foo bar$request_uri is original with query string β unchanged from client$args is query string β $arg_name for specific parameter$host from Host header β $server_name from configPerformance
worker_processes auto β matches CPU coresworker_connections 1024 β per worker, multiply by workers for maxsendfile on β kernel-level file transfergzip on only for text β gzip_types text/plain application/json ...gzip_min_length 1000 β small files not worth compressingLogging
access_log off for static assets β reduces I/Olog_format β add response time, upstream timeerror_log level: debug, info, warn, error β debug is verbosemap and if β skip health checksβ‘ When to Use
User needs Nginx expertise β from basic server blocks to production configurations. Agent handles reverse proxy, SSL, caching, and performance tuning.