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使,
输入一个字符串后在登陆提示框会将该字符串显示出来(相当于提示语)
               
               
               
               
               
               
               

猜你喜欢

转载自www.cnblogs.com/baihualin/p/10896580.html
今日推荐