gpt4 book ai didi

nginx - 如何阻止 nginx 中的空用户代理?

转载 作者:行者123 更新时间:2023-12-05 08:58:42 25 4
gpt4 key购买 nike

我正在尝试全局阻止空用户代理访问服务器上的站点。我已经添加了一个 http_user_agent 拒绝,但它根本不起作用。我这样做对吗..?这是我的 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 - 如何阻止 nginx 中的空用户代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21391929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com