Web server basics-Nginx web service access authentication


This environment is based on the Centos 7.8 system to build the Nginx learning environment. For
specific construction, please refer to Nginx-1.18.0 Environment Deployment

Nginx rewrite is the same as Apache and other web service software, the main function of Nginx rewrite is to realize URL address rewriting. Nginx's rewrite rules need the support of PCRE software, that is, rule matching is performed through Perl compatible regular expression grammar.


1. Access control based on IP address

[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

test

Physical machine
Insert picture description here
rhel7
Insert picture description here
node02
Insert picture description here

Two, based on user access control

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

User Xiaoming failed to access
Insert picture description here
Insert picture description here

wan user access successfully
Insert picture description here
Insert picture description here

Three, based on file access control

[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

test
Insert picture description here

Guess you like

Origin blog.csdn.net/XY0918ZWQ/article/details/113963385
Recommended