一叶知秋.

业精于勤,荒于嬉;行成于思,毁于随。

Nginx的状态统计、目录保护、访问控制

1.nginx的状态统计
#vim /usr/local/nginx/conf/nginx.conf
#在server块中添加:
location /nginx_status{
    stub_status on;
    #开启状态统计
    access_log ogg;
    #状态统计不记录日志
}

#验证:

2.目录保护

以保护状态统计页面为例,配置目录保护
(1)使用http服务的命令htpasswd进行用户和密码文件的创建

htpasswd -c /usr/local/nginx/html/htpasswd.nginx username

(2)在location块中添加如下两行:

auth_basic "Welcome to nginx_status.";
auth_basic_user_file /usr/local/nginx/html/htpasswd.nginx;
location /nginx_status{
    stub_status on;
    access_log ogg;
    auth_basic "Welcome to nginx_status.";
    auth_basic_user_file /usr/local/nginx/html/htpasswd.nginx;
}

(3)重启nginx并再次访问统计页面

/usr/local/nginx/sbin/nginx -s reload

3.访问控制

#基于ip地址的身份验证
在location中添加

allow 10.0.0.102;
deny 10.0.0.0/24
#表示当前location指定的文件仅允许来自10.0.0.102的用户访问

#重启nginx,使用curl验证:

posted @ 2020-08-19 21:05  ccku  阅读(331)  评论(0编辑  收藏  举报