2019.9.23 ngin的访问控制 一共两种认证,第一种是基本认证,第二种是摘要认证

1,基于用户的访问控制

[root@localhost ~]# yum -y install httpd-tools.x86_64    //安装对应软件包

[root@localhost ~]# htpasswd -c -d /usr/local/nginx/conf/xiong tom    //   -c是创建     创建目录xiong    创建用户tom        注意!注意!注意!:如果之前这个xiong的目录里面有用户,加-c的话会清空xiong里面的所有用户。

New password:
Re-type new password:
Adding password for user tom

[root@localhost ~]# chmod 400 /usr/local/nginx/conf/xiong      //给权限

[root@localhost ~]# chown nginx:nginx /usr/local/nginx/conf/xiong       //修改属主 属组

[root@localhost ~]# ll /usr/local/nginx/conf/xiong
-r--------. 1 nginx nginx 18 9月 23 18:37 /usr/local/nginx/conf/xiong

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf       //去主配置文件添加定义的访问控制

server {
listen 80;
server_name www.crushlinux.com;

charset utf-8;


location / {
root html/crushlinux;
index index.html index.htm;
auth_basic "secret"; 
auth_basic_user_file /usr/local/nginx/conf/xiong;            //引用定义的访问控制
}
location /status {
stub_status on;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {

 

测试访问控制,登入用户tom  密码是123456 

 

posted on 2019-09-23 10:57  像鱼拥抱大海  阅读(273)  评论(0编辑  收藏  举报

导航