在公司里面,经常将NGINX作为文件服务器供公司内部员工使用,但在很多情况下,公司针对办公环境和研发环境拥有严格的管控。然而公司办公和研发环境是通过不同的网段进行限制。有时需要通过NGINX的文件服务也能识别到不同的IP段而提供相应的服务。以下则是NGINX针对IP地址的权限控制配置。
nginx.conf:
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 {
}
}