nginx配置指定路径访问白名单

444状态码说明

444是Nginx中特殊的状态码,代表的含义是:Nginx关闭连接而不向客户端发送响应,可以用来抵挡ddos攻击

配置

#user  nobody;
#worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  3000000;
}

http {
	client_max_body_size 1024m; #上传文件大小
    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"';

    geo $allowlist {  #allowlist默认获取的是$remote_addr变量的值
        default 0;
        x.x.x.x 1;
        y.y.y.y 1;
    }
    server {
        listen       80;
        server_name  localhost;
	    location /test/getid {
            if ( $allowlist = 0 ) {
                return 444; 
            }
            proxy_set_header            Host $host;
            proxy_set_header            X-real-ip $remote_addr;
            proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://192.168.2.2:4333/getid;
        }
}
posted @ 2023-12-14 16:34  没脚的丛林鸟  阅读(268)  评论(0编辑  收藏  举报