如何在Nginx中阻止空用户代理?

编程入门 行业动态 更新时间:2024-10-10 13:13:45
本文介绍了如何在Nginx中阻止空用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试全局阻止空用户代理访问服务器上的站点.我添加了一个http_user_agent拒绝,但它根本不起作用.我这样做对吗?这是我的nginx.conf:

I'm trying to globally block empty user agents from accessing sites on the server. I've added a http_user_agent deny, but it doesn't work at all. Am I doing this right..? Here's my nginx.conf:

#user nginx; worker_processes 1; #error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; #pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #tcp_nodelay on; # enable gzip compression gzip on; gzip_min_length 1100; gzip_buffers 4 32k; gzip_types text/plain application/x-javascript text/xml text/css; gzip_vary on; # end gzip configuration server_tokens off; server { if ($http_user_agent ~* (^$)) { return 403; } } include /etc/nginx/conf.d/*.conf; }

推荐答案

if ($http_user_agent = "") { return 403; }

更多推荐

如何在Nginx中阻止空用户代理?

本文发布于:2023-11-06 03:33:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   如何在   Nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!