# 禁用server tokens信息
server_tokens off;
# 限制HTTP方法
limit_except GET POST {
deny all;
}
# 设置安全头部
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Content-Security-Policy "default-src 'self'";
add_header Referrer-Policy "strict-origin-when-cross-origin";
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305';
ssl_ecdh_curve secp384r1;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
# IP白名单
location /admin {
allow 192.168.1.0/24;
allow 10.0.0.1;
deny all;
}
# 速率限制
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
location /api {
limit_req zone=one burst=20 nodelay;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 限制特定文件类型
location ~* \.(php|asp|aspx|jsp)$ {
deny all;
}
[互联网]
|
[外部防火墙] - DMZ区(Nginx反向代理)
|
[内部防火墙] - 应用服务器区
|
[数据库防火墙] - 数据库区
外部防火墙规则:
内部防火墙规则:
Web应用防火墙(WAF):
入侵检测/防御系统(IDS/IPS):
DDoS防护:
log_format security '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time '
'$http_x_forwarded_for';
access_log /var/log/nginx/security.log security;
可疑活动识别:
立即响应措施:
事后分析:
通过结合Nginx的安全配置和企业防火墙策略,可以构建多层防御体系,有效保护企业Web应用和数据安全。