当前位置:   article > 正文

Nginx屏蔽头部攻击_host头攻击解决方案 nginx

host头攻击解决方案 nginx

Nginx屏蔽头部攻击 多IP

nginx正则表达式:
区分大小写匹配: ~
不区分大小写匹配: ~*
区分大小写不匹配: !~
不区分大小写匹配: !~*

nginx 地址重写:

rewrite语句格式
rewrite regex replacement flag;
flag: break、last、redirect、permanent
–last:停止执行其他重写规则,根据URI继续搜索其他location,地址栏不改变
–break:停止执行其他的重写规则,完成本次请求。
–redirect:302临时重定向,地址栏改变,爬虫不更新URI
–permanent:301永久重定向,地址栏改变,爬虫更新URI

location / {
			root html;
			index index.html index.htm;
			rewrite "/a.html$" /b.html;
	}
  • 1
  • 2
  • 3
  • 4
  • 5

nginx域名跳转

www.a.com   --->  www.c.a.cn

server {
		listen 80;
		server_name www.a.com;
		location / {
					root html;
					index index.html index.htm;
					rewrite ^/(.*)  www.c.a.cn/$1;
		}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

简单配置nginx.conf

server {
        listen       80;
        server_name  name1 name2;   ##name可以为域名或者ip
        if ($http_Host !~* ^name1|name2$)    ##name1和name2之间 连接符“|”无任何空格,有空格报错,如果是单域名(ip)省略“|name2”格式为“$http_Host !~* ^name1$”
        {
          return 403;
        }
        location ........
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
nginx -s reload   ##重新加载配置文件
  • 1

禁止非GET|HEAD|POST方式的抓取

详细

if ($request_method !~ ^(GET|HEAD|POST)$) {undefined

return 403;

}
  • 1
  • 2
  • 3
  • 4
  • 5

禁止敏感信息泄露及点击劫持等

# 设置一个无效的值以避免触发真实的主机名
 server_name _;
 server_name_in_redirect off;
#不显示版本号 	 
 server_tokens off;
##添加配置,保证不缺失"Content-Security-Policy"头,当你有很多映射,代理,外网链接时慎用
add_header Content-Security-Policy "default-src 'self' ip:port 'unsafe-inline' 'unsafe-eval' blob: data: ;";   
###添加配置,保证不缺失"X-Content-Type-Options"头
 add_header X-Content-Type-Options nosniff;      
###添加配置,保证不缺失"X-XSS-Protection"头
 add_header X-XSS-Protection "1; mode=block";      
 ####添加配置,保证不点击劫持:X-Frame-Options头
add_header Strict-Transport-Security "max-age=***; includeSubdomains;";   
add_header  X-Frame-Options:DENY;  #"SAMEORIGIN"
add_header 'Referrer-Policy' 'origin'; 
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

nginx限制ip并发连接和请求

nginx限制ip并发连接和请求有两个模块,不需要重新编译安装,nginx默认已经集成。
limit_req_zone  : 限制请求数
limit_conn_zone   :限制并发连接数

limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;  
#zone:=one:10m :设置一个名字为one,大小为10M的缓存空间
#rate=10r/s: 限制访问速率,此处设置为每秒接受10个请求(nging里是按ms及时的,此处为s)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

nginx压力测试

其他常见的压力测试软件:http_load、webbench、siege
  • 1
ab -c 1 -n 10 http://192.168.174.11/    ##-c并发数 -n 请求次数、
  • 1
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号