nginx模块:
基本状态信息:ngx_http_stub_status_module,stub_status
目录中选择一个随机主页:ngx_http_random_index_module,random_index,隐藏文件不会读取到,mv 3.html .3.html
http内容替换:ngx_http_sub_module,sub_filter、sub_filter_once
限制连接频率:ngx_http_limit_conn_module,limit_conn、limit_conn_zone
限制请求频率:ngx_http_limit_req_module,limit_req、limit_req_zone
ab -n 50 -c 20 http://localhost/1.html;发起50个请求,并发为20,测试限制;
基于IP的访问控制:ngx_http_access_module,allow、deny
http_x_forwarded_for=Client IP, Proxy(1) IP,Proxy(2) IP, ...
基于用户的信任登录:ngx_http_auth_basic_module,auth_basic、auth_basic_user_file
生成name1:password1格式文件工具:yum install httpd-tools -y;htpasswd -c ./auth_conf jeson
大文件分片请求:ngx_http_slice_module,slice
静态资源web服务
核心模块:ngx_http_core_module,sendfile、tcp_nopush(提高网络包的传输效率)、tcp_nodelay(提高网络包的传输实时性)
gzip模块:ngx_http_gzip_module,gzip(压缩传输)、gzip_comp_level、gzip_http_version
预读gzip功能:ngx_http_gzip_static_module
应用支持gunzip的压缩:ngx_http_gunzip_module
配置expires
添加Cache-Control、Expires头
Syntax:expires [modified] time;
expires epoch | max | off;
Default:expires off;
Context:http,server,location,if in location
跨域访问:ngx_http_headers_module,add_header
- 浏览器跨域的解决方式有很多种:
- 1.jsonp 需要目标服务器配合一个callback函数。
- 2.window.name+iframe 需要目标服务器响应window.name。
- 3.window.location.hash+iframe 同样需要目标服务器作处理。
- 4.html5的postMessage+ifrme这个也是需要目标服务器或者说是目标页面写一个postMessage,主要侧重于前端通讯。
- 5.CORS需要服务器设置header:Access-Control-Allow-Origin。
- 6.nginx反向代理 这个方法一般很少有人提及,但是他可以不用目标服务器配合,不过需要你搭建一个中转nginx服务器,用于转发请求。
防盗链:ngx_http_referer_module,valid_referers
curl -e http://请求地址 -I http://资源,curl操作资源指向访问
代理服务
正向代理:代理对象是客户端
FQ代理
反向代理:代理对象是服务端
代理模块:ngx_http_proxy_module,proxy_pass
负载均衡
禁用8082端口:iptables -I INPUT -p tcp --dport 8082 -j DROP
upstream模块:ngx_http_upstream_module,upstream、ip_hash、hash
后端服务器在负载均衡调度中的状态:
down 当前server不参与负载均衡
backup 预留的备份server
max_fails 允许请求失败的次数
fail_timeout 经过max_fails后,server暂停时间
max_conns 限制最大的接收连接数
调度算法
轮询 按时间逐一分配server
加权轮询 weight越大分配几率越大
ip_hash ip的hash值分发
least_conn 最少连接数,哪个server少就分发
url_hash url的hash值分发
hash关键数值 hash自定义的key
缓存
代理模块:ngx_http_proxy_module,proxy_cache、proxy_cache_path、proxy_cache_valid、proxy_cache_key、proxy_no_cache
清除cache:
rm -rf 缓存路径
第三方扩展模块ngx_cache_purge
*支持Websocket
*多层代理IP透传
配置SSL证书
甲方提供证书和密钥文件
我方申请证书
在向CA公司申请时可能CA公司会需要证书申请文件,生成方法。
第三方模块
1、后端服务健康检查:nginx_upstream_check_module,check