Nginx常用模块

核心模块:core module
标准模块-HTTP modules
第三方模块:
ngx_http_upstream_module
ngx_http_fastcgi_module模块
ngx_http_headers_module模块
ngx_http_proxy_module模块
ngx_http_rewrite_module模块

ngx_http_upstream_module模块:
1.upstream name { … }

定义后端服务器组,引入一个新的上下文

2.server address [parameters];
在upstream上下文中server成员,以及相关的参数;Context: upstream

        address的表示格式:
            unix:/PATH/TO/SOME_SOCK_FILE
            IP[:PORT]
            HOSTNAME[:PORT]
            
        parameters:
            weight=number
                权重,默认为1;
            max_fails=number
                失败尝试最大次数;超出此处指定的次数时,server将被标记为不可用;
            fail_timeout=time
                设置将服务器标记为不可用状态的超时时长;
            max_conns
                当前的服务器的最大并发连接数;
            backup
                将服务器标记为“备用”,即所有服务器均不可用时此服务器才启用;
            down
                标记为“不可用”;

3.least_conn;

最少连接调度算法,当server权重不同时为wlc

4.ip_hash;

源地址hash调度算法

5.hash key [consistent];

基于指定的key的hash表来实现请求调度

6.keepalive connections;

ngx_http_fastcgi_module模块:
1.fastcgi_pass address;

指定fastcgi地址

2.fastcgi_index name;

指定fastcgi默认访问资源

3.fastcgi_param parameter value [if_not_empty];

指定需要传递给fastcgi的参数

4.fastcgi_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];

定义fastcgi的缓存,缓存位置为磁盘上的文件系统,由path指定的路径来定义,

5.fastcgi_cache zone | off;

调用指定缓存区域来缓存数据

6.fastcgi_cache_key string;

指定用于缓存项的key的字符创

7.fastcgi_cache_methods GET | HEAD | POST …;

指定哪些方法使用缓存

8.fastcgi_cache_min_uses number;

在inactive时间内命中多少次可被视为活动项

9.fastcgi_cache_valid [code …] time;

指定不同响应码缓存的时间

10.fastcgi_keep_conn on | off;

指定是否启用fastcgi长连接

ngx_http_proxy_module模块:
1.proxy_pass URL;

proxy_pass后面的路径不带uri时,其会将location的uri传递给后端主机;

proxy_pass后面的路径是一个uri时,其会将location的uri替换为proxy_pass的uri;

2.proxy_set_header field value;

设定发往后端主机的请求报文的值

3.proxy_cache_path

定义可用于proxy功能的缓存

proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];

4.proxy_cache zone | off;

指定要缓存的区域或关闭缓存功能

5.proxy_cache_key string;

指定缓存中用于“键”的内容

6.proxy_cache_valid [code …] time;

对特定响应码的响应内容缓存的时长

定义在http{...}中;
            proxy_cache_path /var/cache/nginx/proxy_cache levels=1:1:1 keys_zone=pxycache:20m max_size=1g;
            
            定义在需要调用缓存功能的配置段,例如server{...};
            proxy_cache pxycache;
            proxy_cache_key $request_uri;
            proxy_cache_valid 200 302 301 1h;
            proxy_cache_valid any 1m;

7.proxy_cache_use_stale

proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | off ...

8.proxy_cache_methods GET | HEAD | POST …;

请求报文包括列在此处的请求方法是,响应报文使用缓存

9.proxy_hide_header field;

指定nginx将来自被代理服务器响应报文中需要隐藏的报文首部内容

10.proxy_connect_timeout time;

指定nginx与被代理服务器建立连接的超时时间

11.proxy_read_timeout time;

指定读取被代理服务器响应报文的超时时间

12.proxy_send_timeout time;

ngx_http_rewrite_module模块:

rewrite regex replacement [flag]

将用户请求的URI基于regex所描述的模式进行检查,然后完成替换;

注意:如果在同一级配置块中存在多个rewrite规则,那么会自下而下逐个检查;被某条件规则替换完成后,会重新一轮的替换检查,因此,隐含有循环机制;[flag]所表示的标志位用于控制此循环机制;

flag:

    last:重写完成后停止对当前URI在当前location中后续的其他重写操作,而后对新URI启动新一轮重写检查;提前重启新一轮循环

    break:重写完成后停止对当前URI在当前location中后续的其他重写操作,而后直接跳转到重写配置块之后的其他配置;跳过循环

    redirect:重写完成后以临时重定向的方式直接返回重写后的新URI给客户端,由客户端重新发起请求,不能使用http和https开头

    permanent:重写完成后以永久重定向的方式直接返回重写后的新URI给客户端,由客户端发重新发起请求

2.return
return code [text];
return code URL;
return URL;

3.rewrite_log on | off;

是否开启重写日志

4.if (condition) { … }

引入一个新的配置上下文,条件满足时,执行配置块中的配置指令,location,server

condition:
                比较操作符:
                    ==
                    !=
                    ~:模式匹配,区分字符大小写;
                    ~*:模式匹配,不区分字符大小写;
                    !~:模式不匹配,区分字符大小写;
                    !~*:模式不匹配,不区分字符大小写;
                文件及目录存在性判断:
                    -e, !-e 判断是否存在
                    -f, !-f 判断是否存在文件
                    -d, !-d 判断是否存在文件夹
                    -x, !-x 判断是否存在且可执行

5.set $variable value;

ngx_http_ssl_module模块:

1.ssl on | off;

是否对虚拟主机启用https协议

2.ssl_certificate file;

当前虚拟主机使用的pem格式证书文件路径

3.ssl_certificate_key file;

当前虚拟主机使用的证书所对应的私钥文件路径

4.ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];

支持的ssl协议版本,默认支持后三个

5.ssl_session_cache off | none | [builtin[:size]] [shared:name:size];

ssl长连接缓存配置

buildin[ :size ]:使用Openssl内建的缓存,该缓存为此worker独享

shared:name:size:在各worker之间建立一个共享缓存空间

6.ssl_session_timeout time;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值