2、nginx日志
包括:error.log access.log
log_format 设置日志格式:
syntax:log_format name [escape=default|json] string ……;
default:log_format combined “……”;
context:http;
3、nginx变量
http请求变量 arg_parameter、http_header、sent_http_HEADER
内置变量-Nginx内置
自定义变量-自己定义
nginx模块讲解
nginx官方模块
第三方模块
stub_status:
编译选项 | 作用 |
---|---|
—with-http_stub_status_module | NGINX的客户端状态 |
http_stub_status_module配置:
syntax:stub_status;
default:-
context:server,location
eag:
location /mystatus {
stub_status;
}
random_index:**
编译选项 | 作用 |
---|---|
—with-http_random_index_module | 目录中随机选择一个随机主页。 |
http_random_index_module配置:
syntax: random_index on|off;
default: random_index off;
context: location
eag:
location / {
root /opt/app/code;
random_index on;
}
sub_module:
编译选项 | 作用 |
---|---|
—with-http_sub_module | http内容替换 |
http_sub_module配置1:
syntax: sub_filter string replacement;
default: -
context: http,server,location
http_sub_module配置2:
syntax: sub_filter_last_modified on|off;
default: sub_filter_last_modified off;
context: http,server,location
http_sub_module配置3:
syntax: sub_filter_once on|off;
default: sbu_filter_once on; # 值为 on 只匹配第一个
context: http,server,location
eag:
location / {
root /opt/app/code;
index index.html index.htm;
sub_filter '<a>imooc' '<a>IMOOC';
sub_filter_once off;
}
nginx请求限制
分如下两种:
连接评率限制 limit_conn_module
请求评率限制 limit_req_module
http协议的连接与请求:
http请求建立在一次tcp连接基础上
一次tcp请求至少产生一次http请求
连接限制
syntax: limit_conn_zone key zone=name:size;
default: -
context: http
syntax: limit_conn zone number;
default:-
context: http,server,location
请求限制
syntax:limit_req_zone key zone=name:size rate=rate;
default:-
context:http
syntax: limit_req zone=name [burst=number] [nodelay];
default: -
context:http,server,location
nginx访问控制
基于IP的访问控制 http_access_module
基于用户的信任登录 http_auth_basic_module
http_access_module 配置介绍
syntax: allow address | CIDR | unix: | all;
default:-
context: http,server,location,limit_except
syntax: deny address | CIDR | unix: | all;
default: -
context: http,server,location,limit_except
age:
# 限制127.0.0.1 的ip不能访问,其余ip可以访问。
# location ~ ^/admin.html {
# root /opt/app/code;
# deny 127.0.0.1;
# allow all;
# index index.html index.htm;
# }
# 限制127.0.0.1 的ip可以访问,其余ip均不能访问。
location ~ ^/admin.html {
root /opt/app/code;
allow 127.0.0.1;
deny all;
index index.html index.htm;
}
nginx访问控制的局限性
解决nginx访问控制的局限性
http_auth_basic_module模块
syntax: auth_basic string | off;
default : auth_basic off;
context: http,server,location,limit_except
syntax: auth_basic_user_file file;
default: -
context: http,server,location,limit_except
这两个参数要同时出现:auth_basic 定义是否开启与提示信息,auth_basic_user_file 定义用户密码文件的位置。
局限性:
解决方案: