Nginx 配置限制特定域名UA访问,仅允许包含'qyuc'的UA
以下是一个基本的 Nginx 配置,它将特定域名的 UA 限制为只能包含'qyuc':
map $http_user_agent $allowed {
default 0;
'~*qyuc' 1;
}
server {
listen 80;
server_name example.com;
if ($allowed = 0) {
return 403;
}
// other server configurations
}
在上面的配置中,我们使用了map语句来将 UA 映射到一个变量$allowed。如果 UA 包含'qyuc',那么$allowed将被设置为1,否则将被设置为0。
然后,在服务器块中,我们使用if语句来检查$allowed的值。如果它是0,我们会返回403错误,并禁止访问该域名。否则,服务器将正常运行。
这个配置应该放在您的 Nginx 配置文件中的服务器块中。
原文地址: https://www.cveoy.top/t/topic/nwE5 著作权归作者所有。请勿转载和采集!