Nginx 读书摘抄

来源:互联网 发布:mac如何安装win 编辑:程序博客网 时间:2024/06/03 22:00

查看端口和进程的命令:

lsof -i :port
netstat -lntup

Nginx 疑难杂症排除:

报错提示:
1. 用户不存在报错
nginx: [emerg] getpwnam(“nginx”) failed.
原因:没有对应的Nginx服务用户,如果是定义的其他用户,用户不存在都会报此错误。
解决方案:创建对应用户即可

  1. 编译安装pcre,gcc不全导致报错
    解决:安装gcc-c++ 软件包即可

  2. 查看编译Nginx 时的编译参数
    解决方案: nginx -V 就能看的编译安装时的选项。

Nginx 企业应用深入剖析

软件功能说明

  1. Nginx 核心功能模块(core functionality )
  2. 标准的Http 功能模块集合
Nginx http 功能模块 模块说明 ngx_http_core_module 包括一些核心的Http 参数配置, 对应Nginx 的配置为HTTP区块部分 ngx_http_access_module 访问控制模块,用来控制网站用户对Nginx 的访问 ngx_http_gzip_module 压缩模块,对Nginx 返回的数据压缩,属于性能优化模块 ngx_http_fastcgi_module FastCGI模块,和动态应用相关的模块,例如PHP ngx_http_proxy_module proxy 代理模块 ngx_http_upstream_module 负载均衡模块,可以实现网站的负载均衡功能及节点的健康检查 ngx_http_rewrite_module URL地址重写模块 ngx_http_limit_req_module 工具定义的Key限制Nginx 请求过程的速率 ngx_http_limit_req_conn_module 限制也能更好并发连接数及请求数模块 ngx_http_log_module 访问日志模块,以指定的格式记录Nginx 客户访问日志等信息 ngx_http_auth_basic_module web认证模块,设置文本用户通过账号,密码访问Nginx ngx_http_ssl_module ssl模块,用于加密的http连接,如https ngx_http_stub_status_module 记录Nginx基本状态信息等的模块

location 语法

location 的使用语法为:

location [ = | ~ | ~* | ^~ ] uri {    ....}

示例

location = / {    [ configuration A ]    #精确匹配 /}location / {    [ configuration B ]    # 所有正则都不能匹配后,匹配此选项}location /documents/ {    [ configuration C ]    #匹配常规字符串,如果有正则,则优先匹配正则}location ^~ /images/ {    # 匹配常规字符串,不做正则检查    [ configuration D ]}location ~* \.(gif|jpg|jpeg)$ {    [ configuration E ]    # 正则匹配}

在上述location 配置中,当用户请求”/” 时, 将匹配configuration A,当用户请求”/index.html”时,将匹配configuration B,当用户请求”documents/index.html”时,将匹配configuration C, 当用户请求”/images/1.gif”时,将匹配configuration D,当用户请求documents/1.jpg 时,将匹配到configuration E。

Nginx rewrite