Web服务器基础 -- Nginx web服务访问认证

Nginx web服务访问认证

  • 一、基于IP地址访问控制
  • 二、基于用户访问控制
  • 三、基于文件访问控制

本环境是基于 Centos 7.8 系统构建Nginx学习环境
具体构建,请参考 Nginx-1.18.0 环境部署

Nginx rewrite和 Apache 等 Web 服务软件一样, Nginx rewrite 的主要功能也是实现 URL 地址重写。Nginx的rewrite 规则需要 PCRE 软件的支持, 即通过 Perl 兼容正则表达式语法进行规则匹配。


一、基于IP地址访问控制

[root@node01 ~]# vim /etc/nginx/conf.d/host.conf 
    server {
     
        listen       192.168.5.11:80;
        server_name  bbs.123.cn;
        location / {
     
            root   /usr/share/nginx/html/bbs;
            index  index.html index.htm;
            deny 192.168.5.12;
            allow 192.168.5.0/24;
            deny all;
        }
}

[root@node01 ~]# nginx -s reload

测试

物理机
Web服务器基础 -- Nginx web服务访问认证_第1张图片
rhel7
在这里插入图片描述
node02
Web服务器基础 -- Nginx web服务访问认证_第2张图片

二、基于用户访问控制

[root@node01 ~]# yum install httpd-tools -y
[root@node01 ~]# htpasswd -c /etc/passwd wan

小明用户 访问失败
Web服务器基础 -- Nginx web服务访问认证_第3张图片
在这里插入图片描述

wan用户 访问成功
Web服务器基础 -- Nginx web服务访问认证_第4张图片
Web服务器基础 -- Nginx web服务访问认证_第5张图片

三、基于文件访问控制

[root@node01 ~]# vim /etc/nginx/conf.d/host.conf 
    server {
     
        listen       192.168.5.11:80;
        server_name  bbs.123.cn;
        location / {
     
            root   /usr/share/nginx/html/bbs;
            index  index.html index.htm;
        location ~ \.txt{
     
            deny all;
           }
        }
}
[root@node01 ~]# nginx -s reload

测试
Web服务器基础 -- Nginx web服务访问认证_第6张图片

你可能感兴趣的:(Web,Server,Clusters,Web集群,Nginx,web服务访问认证,运维)