nginx 实现不同目录IP访问限制

432 阅读1分钟

如下配置主要实现不同目录的IP访问限制:

server {
    listen       8000 default_server;
    server_name  _;
    root         /data/;
    charset     utf8,gbk;
    include /etc/nginx/default.d/*.conf;

    location / {
        autoindex on;
    }
    
    location /test1/ {
        allow   10.0.0.0/24;
        allow   10.0.0.100/32;
        deny    all;
        autoindex on;
    }
    
    location /test2/ {
        allow   10.0.1.0/24;
        allow   10.0.1.100/32;
        deny    all;
        autoindex on;
    }

    location /test3/ {
        autoindex on;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}