记录Nginx模块开发

时间:2023-03-08 22:41:04
  • --with-http_stub_status_module模块:Nginx的客户端状态

Syntax:stub_status

Default:--

Content:server,location

location /mystatus{

stub_status;

}

>>效果图

记录Nginx模块开发

  • --with-http_random_index_module模块:目录中选择一个随机主页

Syntax:random_index on|off

Default:random_index off;

Content:location

location /{

root  随机文件的文件夹;

random_index on;

}

  • --with-http_sub_module模块:http内容替换

Syntax:sub_filter string replacement

Default:--

Content:http,server,location

location /{

sub_filter '被替换值' '替换值';

}

  • --with-http_limit_conn_module模块:连接限制

Syntax:limit_conn_zone key zone=name:size;

Default:--

Content:http

Syntax:limit_conn [zone] number;

Default:--

Content:http,server,location

limit_conn_zone $binary_remote_addr zone=conn_zone:1m;

server{  

  location / {

limit_conn conn_zone 1;

  }

}

  • --with-http_limit_req_module模块:请求限制

Syntax:limit_req_zone key zone=name:size rate=size;

Default:--

Content:http

Syntax:limit_req zone=name [burst=number][nodelay];

Default:--

Content:http

limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s;

server{  

  location / {

#limit_req zone=req_zone;

#limit_req zone=req_zone burst=3;

#limit_req zone=req_zone burst=3 nodelay;
}

  • --with-http_access_module模块:访问控制-基于IP的访问控制

Syntax:allow address | CIDR | unix: |all;

Default:--

Content:http,server,location,limit_except;

Syntax:deny address | CIDR | unix: |all;

Default:--

Content:http,server,location,limit_except;

server{  

  location / {

root   /usr/share/nginx/html;

index  index.html index.htm;

}

location ~^ / 50x.html {

root   /usr/share/nginx/html;

#allow 117.30.57.5;

#allow 117.30.57.5/40;#允许5-40IP地址段访问

deny all;

}

}

  • --with-http_auth_basic_module模块:访问控制-基于用户的信任登陆

Syntax:auth_basic string|off;

Default:auth_basic off;

Content:http,server,location,limit_except

Syntax:auth_basic_user_file file;

Default:--

Content:http,server,location,limit_except