nginx典型官方模块解释

模块名称  作用语法默认配置位置配置举例结果验证备注
1 --with-http_stub_status_module监控Nginx的服务器连接状态stub_status server、location这一级来配置location = /mystatus{
        stub_status;
    }
此时访问http://127.0.0.1/mystatus
即可查看现在有nginx现在有多少连接了
 
2 --with-http_random_index_module目录中选择随机一个页面作为主页random_index on|off  location这一级来配置 location / {
        root   /usr/share/nginx/html;
        #index  index.html index.htm;
        random_index on;
    }
  不会随机到隐藏文件
 3 --with-http_sub_module HTTP内容替换 1、sub_filter '要替换的字符' '替换后的字符'
2、sub_filter_last_modified on|off
3、sub_filter_once on|off
  http、server、location这一级来配置 location / {
        root   /usr/share/nginx/html;
        #index  index.html index.htm;
        random_index on;
        sub_filter '1' '2';
        sub_filter_once off;
    }
 2、用于服务端和浏览器端进行每一次请求的时候校验服务端是否有发生过变更
3、为on时只替换第一个匹配到的;
   为off时替换全部匹配到的
 4 -limit_conn_module 连接频率限制 

1、limit_conn_zone key zone=name:size; key:以key为依据来限制频率(例:key为源IP) name:保存连接数需要一块内存,name为这块内存地址 size:name这块内存的大小 其余为关键字

2、limit_conn zone number; zone:为1中的name number:限制的大小(例:限制源IP为1.1.1.1的并发为1000)

 1、http这一级来配置
2、http、server、location这一级来配置
 http{
limit_conn_zone $remote_addr zone=abc:10m;
  server {
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
          limit_conn zone zone=bcd 1;
      }
  }
}
 实验没做成功,NND 一个TCP连接为一个连接,在一个TCP连接里可以有多个HTTP连接
(即:TCP三次握手一次后就可以发送多个http请求了。即:单路复用) 
 5 -limit_req_module 请求频率限制 

1、limit_req_zone key zone=name:size rate=rate key、name、size同limit_conn_module rate:以秒为单位的频率(例:每秒100次请求)

2、limit_req zone=name [burst=number][nodelay] name:为1中的name [burst=number]:选填,number为客户端在超过速率后的前number个放到下一秒执行 [nodelay]:选填,超过速率的直接返回503

  1、http这一级来配置
2、http、server、location这一级来配置
 http{
limit_req_zone $remote_addr zone=bcd:1m rate=1r/s;
  server {
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
          limit_req zone=bcd burst=3 nodelay;
      }
  }
}
 限定每秒请求为1时,在1秒内访问2次的话第二次返回503.
(小米抢手机估计就是用的这套路)
 6 -http_access_module 基于IP的访问控制 1、allow address|CIDR|unix:|all
2、deny address|CIDR|unix:|all
  http、server、location、limit_except这一级来配置 location ~ ^/admin.html {
        root   /var/log/html/;
        deny 172.20.163.127;
        allow all;
    } 
 172.20.163.127访问主页时会返回403,其他正常 ~ ^/admin.html:代表要访问admin.html这个页面时去/var/log/html/取找。
管理后台只对指定IP开放可以用这个方法
 7 -http_auth_basic_module 基于用户的信任登陆 1、auth_basic string|off;
2、auth_basic_user_file file;
  http、server、location、limit_except这一级来配置 

location / {

      root   /usr/share/nginx/html;        

      index  index.html index.htm;        

      auth_basic 'input password:';        

      auth_basic_user_file /passwd.txt;

}

htpasswd -c /passwd.txt liwei   ====>使用htpasswd生成保存账号的文件,普通文本nginx不识别

  auth_basic string|off;这里的string输入一个字符串后也当on使,
输入一个字符串后在登陆提示框会将该字符串显示出来(相当于提示语)
        
        
        
        
        
        
        

转载于:https://www.cnblogs.com/baihualin/p/10896580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值