首页 > IT基础架构 > 网络安全 > 渗透测试基础知识---nginx安全配置
`http { server_tokens off;}`
server {
listen 443;
server_name xxx.com;
ssl on;
ssl_certificate /etc/nginx/certs/xxx.com.pem;
ssl_certificate_key /etc/nginx/certs/xx.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
}
`location /admin/ { allow 192.168.1.0/24; deny all;}`
`location /uploads/ { deny 192.168.1.0/24; allow all;}`
`set $allow false;if ($http_x_forwarded_for = "211.144.204.2") { set $allow true; }if ($http_x_forwarded_for ~ "108.2.66.[89]") { set $allow true; }if ($allow = false) { return 404; }`
server {
location / {
auth_basic "please input user&passwd";
auth_basic_user_file key/auth.key;
}
}
if ($request_method !~ ^(GET|POST)$ ) {
return 405;
}
location / {
limit_except GET HEAD POST { deny all; }
}
if ($http_user_agent ~* LWP::Simple|BBBike|wget|curl) {
return 444;
}
location /images/ {
valid_referers none blocked xx.com;
if ($invalid_referer) {
return 403;
}
}
location /images/ {
valid_referers blocked xx.com
if ($invalid_referer) {
rewrite ^/images/.*.(gif|jpg|jpeg|png)$ /static/qrcode.jpg last;
}
}
http {
limit_conn_zone $binary_remote_addr zone=ops:10m;
server {
listen 80;
server_name xx.com;
root /home/project/webapp;
index index.html;
location / {
limit_conn ops 10;
}
access_log /var/log/nginx/nginx_access.log main;
}
}
limit_conn_zone
:设定保存各个键(例如$binary_remote_addr)状态的共享内存空间的参数,zone=空间名字:大小大小的计算与变量有关limit_conn:
指定一块已经设定的共享内存空间
(例如name为ops的空间),以及每个给定键值的最大连接数client_body_buffer_size 1K;
client_header_buffer_size 1k;
client_max_body_size 1k;
large_client_header_buffers 2 1k;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
location ~/\.ht {
deny all;
}
location ~ ^/(picture|move)/ {
deny all;
break;
}
location ~ ^/data {
deny all;
}
location /imxhy/images/ {
deny all;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70006652/viewspace-2886036/ ,如需转载,请注明出处,否则将追究法律责任。