天天看點

nginx 基于http_x_forwarded_for通路控制白名單

map $http_x_forwarded_for $accessip {
    default false;
    10.10.10.10 true;  #定義白名單
}
server {
    listen       80;
    server_name 127.0.0.1;
    root html;
    access_log logs/access.log main;
    error_log  logs/error.log;
    #expires -1;
    location /favicon.ico {
            expires 30d;
    }
    location / {
        if ( $accessip = 'false' ) {return 403;} #通路控制
        try_files $uri @fallback;
    }
}