nginx进程模型
- 谁先竞争到内存中accept_mutex谁处理下一个请求。
- master进程
- worker进程
- Syntax: worker_processes number | auto;
Default: worker_processes 1;
- cache Manager进程
- cache loader进程
- 进程间通讯使用共享内存
nginx进程管理:信号
不停机载入新配置
reload:启动新进程
线上nginx 平滑添加新模块;如(—with-http_realip_module)
不停机更新nginx版本
GoAccess监控nginx
模块
-
postread阶段
realip模块
$remote_addr默认是上一级的IP。
编译安装:./configure —prefix=/usr/local/nginx-1.4.1 —with-http_realip_module
变量:
- realip_remote_addr:tcp中的源ip。
- realip_remote_port
指令:
- set_real_ip_from
- real_ip_header
- real_ip_recursive
rewrite
- last:用replacement这个url 重新进行location匹配。
- break:break指令停止当前脚本的执行,不再匹配。
- redirect:返回302重定向。
- permanent:返回301重定向。
-
location
location [=|~|~*|^~|@] /uri/ { … }
= : 表示精确匹配后面的url
- ~ : 表示正则匹配,但是区分大小写
- ~* : 正则匹配,不区分大小写
- ^~ : 表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录
@ : “@” 定义一个命名的 location,使用在内部定向时,例如 error_page
限流:limit_req&limit_conn
limit_conn模块
precontent阶段
mirror模块:拷贝流量
content阶段
static模块
root&alias
变量
- request_filename : 磁盘文件系统待访问文件的完整路径;
- document_root : 由URI和root/alias规则生成的文件夹路径;
- realpath_root : 将document_root中的软连接换成真实路径;
重定向三个配置
absolute_redirect ,server_name_in_redirect和port_in_redirectconcat模块
需要编译nginx
合并文件传输,对http2没有意义。sub_filter:替换响应字符串
addition模块:添加内容
需要编译
变量
tcp变量
valid_referers:防盗链
map模块
geo模块
返回变量$country
geoip
需要编译
proxy_pass和fastcgi_pass区别
fastcgi 取代了Apache
CGI,FastCGI 都是协议,说白了就是一个约定,或者设计方法!!和HTTP协议是一个概念。(FastCGI是CGI的进阶版,设计更好,所以能提升性能) PHP-FPM是一个程序,是用来管理PHP-CGI的。(PHP-CGI是基于FastCGI的一个具体实现)
作者:陈涛 链接:https://www.zhihu.com/question/30672017/answer/388529330 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。