server {} 里加入以下内容:

location ~* /admin {
    allow 192.168.1.100;
    allow 192.168.1.101;
    deny all;
}


注:~* 不区分大不写

 如果admin目录下有php文件,还需要加入以下内容,才能访问php程序。

location ~ \.php {
        root  /opt/www/web;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /opt/www/web/$fastcgi_script_name;
        include        fastcgi_params;
}


如果nginx是前端服务器,还需加入以下内容:


proxy_pass http://web;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;