nginx_模块相关

 参考文档:http://shouce.jb51.net/nginx/

认证模块

        
            yum install httpd-tools -y
 
        
            Syntax:    auth_basic string | off;    如果跟string,就代表开启。
            Default:    
            auth_basic off;
            Context:    http, server, location, limit_except
            
            1、生成密码
            [root@web02 conf.d]# htpasswd -c /etc/nginx/auth chenyang
 
            2、配置加密
            auth_basic "This is Auth Basic!";
            auth_basic_user_file /etc/nginx/auth;
 
 
            在命令行中的访问方式
            [root@m01 ~]# curl -H'Host: index.test.com' http://chenyang:123456@192.168.15.8
    
 
 
 
 
 
    

Nginx状态模块

        
            location /status {
                stub_status;
            }
   
 
 
 
 

     访问控制模块

        3、禁用IP和开放IP访问
        
            allow    : 允许IP访问
            deny    :禁止IP访问
            
            案例1:只允许192.168.15.1来访问。
                
                1、允许192.168.15.1来访问
                
                    allow 192.168.15.1;
                    
                2、禁止其他所有IP来访问
                
                    deny all;
            

server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
allow 192.168.15.1
deny all
location / {
root html;
index index.html index.htm;
}

 

            案例2:只允许192.168.15.0来访问。
            
                
                1、允许192.168.15.0来访问
                
                    allow 192.168.15.0/24;
                
                2、禁止其他所有IP来访问
                
                    deny all;
                

server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
allow 192.168.15.0/24;
deny all;
location / {
root html;
index index.html index.htm;
}

            案例3:要求禁止192.168.15.1来访问。
            
                1、禁止192.168.15.1来访问
                
                    deny 192.168.15.1;
                
                2、允许其他所有的IP来访问
                
                    allow all;

server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
deny 192.168.15.1;
allow all;
location / {
root html;
index index.html index.htm;
}

            
     
 
 
 
 
 
       
        

目录索引模块

        
            # 开启目录索引
            autoindex on;
            # 格式化文件大小
            autoindex_exact_size off;
            # 输出的格式
            autoindex_format html;
            # 使用时区
            autoindex_localtime on;
      
 
 
 
  

限制连接数模块

        
            1、创建一个内存空间存放访问者的IP
            
            2、设置每一个访问者的同时连接次数
        
        6、限制请求数模块
        
            1、创建一个内存空间存放访问者的IP
            
            2、设置每一个访问者的同时请求次数
            [root@web02 conf.d]# cat game.conf
            # 创建一个叫linux的空间,主要用来存放客户端IP,大小给10M
            limit_conn_zone $remote_addr zone=linux:10m;
 
            limit_req_zone $remote_addr  zone=python:10m rate=1r/s;
 
            server {
                server_name game.test.com;
                listen 80;
                location / {
                    # 调用linux空间, 限制连接数为1
                    # limit_conn linux 1;
                    limit_req zone=python burst=5;
                    root /usr/share/nginx/html5-mario;
                    index index.html;
                }
            }
 
     
 
        知识储备:
        
            ab : 创建请求的命令,(yum install httpd-tools -y )
            
                -c : 设置并发
                -n :  设置请求的总数
posted @ 2021-10-27 21:40  念长卿  阅读(37)  评论(0)    收藏  举报