image.png
image.png

nginx进程模型

image.png
Nginx - 图5
image.png
image.png

  • 谁先竞争到内存中accept_mutex谁处理下一个请求。

Nginx 为什么这么快?_朱小厮的博客-CSDN博客

  • master进程
  • worker进程
    • Syntax: worker_processes number | auto;

Default: worker_processes 1;

  • cache Manager进程
  • cache loader进程
  • 进程间通讯使用共享内存


image.png

nginx进程管理:信号

image.png

不停机载入新配置

image.png
reload:启动新进程

变量:

  • realip_remote_addr:tcp中的源ip。
  • realip_remote_port

指令:

  • set_real_ip_from
  • real_ip_header
  • real_ip_recursive

image.png

rewrite

image.png

  • last:用replacement这个url 重新进行location匹配。
  • break:break指令停止当前脚本的执行,不再匹配。
  • redirect:返回302重定向。
  • permanent:返回301重定向。
  • rewrite_log on;

    location

    location [=|~|~*|^~|@] /uri/ { … }

  • = : 表示精确匹配后面的url

  • ~ : 表示正则匹配,但是区分大小写
  • ~* : 正则匹配,不区分大小写
  • ^~ : 表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录
  • @ : “@” 定义一个命名的 location,使用在内部定向时,例如 error_page

    限流:limit_req&limit_conn

  • limit_conn模块

image.png

  • limit_req模块

    access阶段

    allow&deny:ip限制

    image.png

    auth_basic:密码

    auth_request:第三方鉴权

    image.png

precontent阶段

mirror模块:拷贝流量

image.png

content阶段

static模块

root&alias

image.png

变量

  • request_filename : 磁盘文件系统待访问文件的完整路径;
  • document_root : 由URI和root/alias规则生成的文件夹路径;
  • realpath_root : 将document_root中的软连接换成真实路径;

    重定向三个配置

    absolute_redirect ,server_name_in_redirect和port_in_redirect

    concat模块

    需要编译nginx
    合并文件传输,对http2没有意义。

    sub_filter:替换响应字符串

    image.png

    addition模块:添加内容

    需要编译
    image.png

变量

image.png
image.png
image.png
image.png
image.png
tcp变量
image.png
image.png
image.png
image.png

valid_referers:防盗链

image.png

map模块

geo模块

返回变量$country
image.png

geoip

需要编译
image.png

proxy_pass和fastcgi_pass区别

fastcgi 取代了Apache
Nginx - 图35

CGI,FastCGI 都是协议,说白了就是一个约定,或者设计方法!!和HTTP协议是一个概念。(FastCGI是CGI的进阶版,设计更好,所以能提升性能) PHP-FPM是一个程序,是用来管理PHP-CGI的。(PHP-CGI是基于FastCGI的一个具体实现)

作者:陈涛 链接:https://www.zhihu.com/question/30672017/answer/388529330 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。