- 配置的嵌套块格式
- 指令的合并
1、值指令:存储配置项的值
如:root、access_log、gzip
存储值的指令继承规则:向上覆盖,即:子配置不存在时,直接使用父配置块;子配置存在时,直接覆盖父配置块
2、动作类指令:指定行为
如:rewrite、proxy_pass
生效阶段:server_rewrite阶段、rewrite阶段、content阶段
示例:
listen unix:/var/run/nginx.sock;
listen 127.0.0.1:8000;
listen 127.0.0.1;
listen 8000;
listen *:8000;
listen localhost:8000 bind;
listen [::]:8000 ipv6only=on;
listen [::1];
- 接收请求事件模块
- 接收请求HTTP模块
- 常用正则表达式
- server匹配顺序(以下优先级由高到低依次排序)
1、精确匹配
2、*在前的泛域名
3、*在后的泛域名
4、按文件的顺序匹配正则表达式域名
5、default server(①没有指定默认第一个server ②server块listen中指定了default)
- HTTP请求处理的11个阶段(详见原文档)
- 【POST_READ阶段】
- realip模块(详见:http://nginx.org/en/docs/http/ngx_http_realip_module.html)
- 【SERVER_REWRITE阶段】
- rewrite模块(详见:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html)
1、return指令(详见:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return)
2、return指令与error_page使用(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page)
3、rewrite指令(详见:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite)
4、rewrite_log指令(详见:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite_log)
5、if指令(详见:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if)
-
location指令块(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#location)
- 【PREACCESS阶段】
- limit_conn模块(详见:http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html)
- limit_req模块(详见:http://nginx.org/en/docs/http/ngx_http_limit_req_module.html)
- 【ACCESS阶段】
- access模块(详见:http://nginx.org/en/docs/http/ngx_http_access_module.html)
- auth_basic模块(详见:http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html)
- auth_request模块(详见:http://nginx.org/en/docs/http/ngx_http_auth_request_module.html)
1、限制所有access阶段模块的satisfy指令(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#satisfy)
- 【precontent阶段】
- try_files指令(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)
- 【CONTENT阶段】
- root和alias指令(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#root 、http://nginx.org/en/docs/http/ngx_http_core_module.html#alias)
types(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#types)
default_type(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type)
types_hash_bucket_size(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#types_hash_bucket_size)
types_hash_max_size(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#types_hash_max_size)
log_not_found(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#log_not_found)
- 重定向
server_name_in_redirect(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name_in_redirect)
port_in_redirect(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#port_in_redirect)
absolute_redirect(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#absolute_redirect)
- index模块(详见:http://nginx.org/en/docs/http/ngx_http_index_module.html)
- autoindex模块(详见:http://nginx.org/en/docs/http/ngx_http_autoindex_module.html)
- concat模块(详见:https://github.com/alibaba/nginx-http-concat)
示例:
nginx.conf配置:
location /static {
concat on;
concat_types text/plain;
concat_unique on;
concat_max_files 30;
concat_delimiter ':::';
}
请求地址格式:
http://example.com/static/??a.txt,b.txt
返回的内容以:::分隔两个文件的内容
- 【LOG阶段】
- log模块(详见:http://nginx.org/en/docs/http/ngx_http_log_module.html)
- 【HTTP过滤模块】
- addition模块(详见:http://nginx.org/en/docs/http/ngx_http_addition_module.html)
- Nginx变量的运行原理
- secure_link模块(详见:http://nginx.org/en/docs/http/ngx_http_secure_link_module.html)
- split_clients模块(详见:http://nginx.org/en/docs/http/ngx_http_split_clients_module.html)
IP代理地址:http://www.goubanjia.com/
页面地址:https://dev.maxmind.com/geoip/geoip2/downloadable/
Geoip下载地址:https://github.com/maxmind/geoip-api-c
GeoLiteCity下载地址:http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
- keepalive模块(详见:http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable、http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_requests、http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout)