Security Best Practices in Nginx
From the Nginx cheat sheet · Security & Access Control · verified Jul 2026
Security Best Practices
Essential security configurations
nginx
# Hide Nginx version
server_tokens off;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# IP restrictions
location /admin {
allow 192.168.1.0/24;
deny all;
}🔒 Always hide server version information
🛡️ Implement security headers
⚠️ Use rate limiting to prevent abuse
🔐 Restrict access to sensitive areas