nginx子產品
http_substitutions_filter_module
modsecurity
Tengine支援了動态加載子產品
增加modsecurity子產品
modsecurity傾向于過濾和阻止web危險
http://waringid.blog.51cto.com/65148/1629905
關閉伺服器标記 http{server_tokens off} 隐藏nginx版本
自定義緩存
server
{
client_body_buffer_size 16K;
client_header_buffer_size 1k;
client_max_body_size 1m;
large_client_header_buffers 4 8k;
}
設定timeout設低來防禦DOS攻擊
http
client_body_timeout 10;
client_header_timeout 30;
keepalive_timeout 30 30;
send_timeout 10;
限制通路的方法
if($request_method !~ ^(GET|HEAD|POST)$) {
return404;
}
實際中應該使用444
日志切割
kill-USR1 $(cat /var/run/nginx/nginx.pid)
子產品 ngx_http_access_module 允許限制某些IP位址的用戶端通路
location/ {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
在原來的編譯參數的首行加入--add-module=/root/install/naxsi-core-0.51-1/naxsi_src
nbs.rules檔案
增加IP限制功能
子產品ngx_http_limit_conn_module和來ngx_http_limit_req_module
http {
limit_req_zone$binary_remote_addr zone=one:10m rate=10r/s;
limit_conn_zone$binary_remote_addr zone=two:10m;
}
server{
limit_req zone=one burst=5;
limit_conn two 15;
增加WAF子產品
增加fail2ban防止非法IP
ngx_http_stub_status_module 子產品
Nginx子產品GeoIP比對處理IP所在國家、城市
if ( $geoip_country_code !~ ^(CN|US)$ ) {
return 403;
自定義nginx版本号
http://purplegrape.blog.51cto.com/1330104/1291871
封殺各種user-agent
if ($http_user_agent ~* "java|python|perl|ruby|curl|bash|echo|uname|base64|decode|md5sum|select|concat|httprequest|httpclient|nmap|scan" ) {
return 403;
if ($http_user_agent ~* "" ) {
封殺特定的url
location ~* \.(bak|save|sh|sql|mdb|svn|git|old)$ {
rewrite ^/(.*)$ $host permanent;
location /(admin|phpadmin|status) { deny all; }
封殺特定的http方法和行為
if ($request_method !~ ^(GET|POST|HEAD)$ ) {
return 405;
if ($http_range ~ "\d{9,}") {
return 444;
強制網站使用域名通路,可以逃過IP掃描
if ( $host !~* 'abc.com' ) {
url 參數過濾敏感字
if ($query_string ~* "union.*select.*\(") {
rewrite ^/(.*)$ $host permanent;
}
if ($query_string ~* "concat.*\(") {
強制要求referer
if ($http_referer = "" ) {
}
老外的配置
set $add 1;
location /index.php {
limit_except GET POST {
deny all;
}
set $ban "";
if ($http_referer = "" ) {set $ban $ban$add;}
if ($request_method = POST ) {set $ban $ban$add;}
if ($query_string = "action=login" ){set $ban $ban$add;}
if ($ban = 111 ) {
access_log /var/log/[133]nginx/ban IP;
return 404;
proxy_pass http://127.0.0.1:8000; #here is a patch
}
目錄隻讀
mount --bind /data /var/www/html
mount -o remount,ro --bind /data /var/www/html
極大程度上可以防止提權篡改
本文轉自 liqius 51CTO部落格,原文連結:http://blog.51cto.com/szgb17/1710068,如需轉載請自行聯系原作者