Nginx访问控制模块
nginx -V : 查看已下载模块
允许或者拒绝某些IP访问
deny : 拒绝
allow : 允许
案例1:允许192.168.15.1访问,不允许其他IP访问
allow 192.168.15.1;
deny all;
案例2:允许192.168.15.0这个网段访问,不允许其他网段访问
allow 192.168.15.0/24;
deny all;
案例3:只允许通过VPN来访问
allow 172.16.1.81;
deny all;
访问之前需要登录
1、安装httpd-tools
[root@web01 ~]# yum install httpd-tools -y
2、生成用户名密码文件
[root@web01 ~]# htpasswd -c /etc/nginx/auth UPythonFish
New password:
Re-type new password:
Adding password for user UPythonFish
3、将文件路径加入Nginx配置
[root@web01 ~]# vim /etc/nginx/conf.d/game.conf
auth_basic "Welcome To Login";
auth_basic_user_file /etc/nginx/auth;
4、重启Nginx
[root@web01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 ~]# systemctl restart nginx
展示目录索引。
autoindex on | off;
# 启用或禁用目录列表输出 默认 autoindex off;
autoindex_exact_size on | off;
# 对于 HTML格式,指定是否应在目录列表中输出确切的文件大小 默认 autoindex_exact_size on;
autoindex_localtime on | off;
# 对于 HTML格式,指定目录列表中的时间是否应以本地时区或 UTC 输出。 默认 autoindex_localtime off;
autoindex_format html | xml | json | jsonp;;
# 设置目录列表的格式。 默认 : autoindex_format html;