一? ? buffer相关的参数
? ? ?proxy_buffer_size ?????proxy_buffering ?????proxy_buffers ?????proxy_busy_buffers_size
二? ? cache相关的参数 了解??
?????proxy_cache ?????proxy_cache_background_update ?????proxy_cache_bypass ?????proxy_cache_convert_head ?????proxy_cache_key ?????proxy_cache_lock ?????proxy_cache_lock_age ?????proxy_cache_lock_timeout ?????proxy_cache_max_range_offset ?????proxy_cache_methods ?????proxy_cache_min_uses ?????proxy_cache_path ?????proxy_cache_purge ?????proxy_cache_revalidate ?????proxy_cache_use_stale ?????proxy_cache_valid
? ? ?proxy_no_cache
三? ? cookie相关
cookie问题汇总? nginx跨域配置
①? ??proxy_cookie_domain
(1)基础知识铺垫

Cookie头的属性



(2)指令解读
细节点:
1) 如果'proxy server'中'Set-Cookie'没有"domain属性"或者有"domain属性"但是不匹配则'nginx'不做"domain"操作
2) proxy_cookie_domain负责的'只是处理response set-cookie头中的domain属性',仅此而已

?proxy_cookie_domain的误区
?proxy_cookie_domain应用场景
②? ? ?proxy_cookie_path
为什么cookie会丢失
(1)基础知识铺垫

(2)指令解读

(3)案例说明

'前后段分离':console nginx设置了cookie path,cookie缓存'导致403',删除cookie path
策略:proxy_cookie_path / "/;secure"
③?? ?proxy_cookie_flags
应用场景
Cookies
(1)基础知识铺垫
Cookie samesite简析


?Cookie的secure属性

Cookie中的httponly的属性和作用、httponly属性
用于认证的关键 Cookie,建议'都加上' HttpOnly 标识

nginx 反向代理 解决 Cookie 跨域问题
四? ? timeout相关的
?? ? proxy_connect_timeout
? ? ?proxy_read_timeout
? ? ?proxy_send_timeout
proxy_connect_timeout
1) 后端服务器连接的超时时间,发起'握手等候响应'超时时间(代理'连接'超时)默认60s
proxy_read_timeout
1)它决定了nginx会'等待多长时间'来获得请求的响应('响应超时')默认值60s
proxy_send_timeout
1)后端服务器'数据回传时间',就是在规定时间之内后端服务器'必须传完'所有的数据(代理发送超时)默认值60s
五? ? pass相关 重点
①??proxy_pass
dns解析引发对proxy_pass的思考
+++++++++ proxy_pass'构成' +++++++++
"协议[http、https]"+"//"+"域名[ip]"+"端口(http默认是80,https默认是443)"+"option[可选]的uri"
(1)基本解读?

++++++++'proxy_pass的形式'++++++++
字面值ip、'域名'、'upstream_id'、'变量[表示域名]' -->四种方式设置'上游[回源-->CDN中]'地址
1)有'变量',先'预'编译,'reload|restart'不会报错,等'客户端的请求'来了再'handle处理'
方式1: '自定义变量'
set $target www.baidu.com;
proxy_pass http://$target;
方式2: '客户端传递的http变量'
proxy_pass http://http_target;
特性:服务'启动'的时候,'绕过域名检查'
2)无'变量'
dns解析的问题?
(2)URI三种类型的前两种
+++++++++"proxy_pass两种类型"的讨论+++++++++
1)一种是'只包含ip和port'的-->"没有后面的/" --> "不带URI"
形如:https://www.wzj.com:8080
2)端口号之后'有其他路径'的 -->"带URI的"
[1]、https://www.wzj.com:8080/
[2]、https://www.wzj.com:8080/abc
备注:这两种类型的'处理方式不同'
对比:'origin request_uri'、'location的规则'、'proxy_pass的URI'
nginx中不起眼的/?

1)测试1? proxy_pass 无URI?
??




2)测试2? URI?带/



?3)测试3
'/abc[proxy_passs的uri]' + ('/ceshi/hello.html[origin]' - '/ceshi/[location的uri]')
'拼接的结果'--> '/abchello.html'
()'计算结果' --> 相对location的'剩余'路径




4)测试4
'/abc/[proxy_passs的uri]' + ('/ceshi/hello.html[origin]' - '/ceshi/[location的uri]')
'拼接[代理转发]的结果'--> '/abc/hello.html'




5)测试5? 注意//双斜杠



(3) 第三种? ?nginx无法确认uri的替换规则

第三个解读: 'proxy_pas'有值,但是又要将客户'原有的请求uri'转到到目标机器,使用'$request_uri'变量
?1)案例1
1)原来'错误'的理解
当'location'带有'~、~* [以~开头]'正则时,proxy_pass'不允许'有'URI [不管是变量、文本、还是混合的形式]'
2) '修证后'的理解
如果location使用'正则'表达式,proxy_pass中'不能指定[裸]path{最终path}',除非proxy_pass中包含'变量'
+++++++++ "以下是两个对比案例" +++++++++
重点'关注'混合场景: location指定的是"正则表达式"和"proxy_pass配置的url中带变量"混合场景了


参考链接
 


++++++++++++++ "扩展学习" ++++++++++++++
location /abc/d {
if ( $request_uri ~ /abc/d/(.+) ) {
set $args $1;
}
proxy_pass https://backend/ef/$args;
}
============'等价'方式============
location ~ /abc/d/(.+) {
proxy_pass https://backend/ef/$1;
}
?2)案例2
1)rewrite改变'uri',此时'proxy_pass'的'uri'被'ignored'忽略

?


3)案例3
1)当uri中携带'变量',会用'proxy_pass中解析后的uri'替换'origin request',作为最终转发到后端的'uri'
备注:注意与'案例1'的差异点




案例讲解
案例学习
使用变量
②??proxy_pass_header?
应用场景: nginx'放通'某些'禁止'透传的响应头

X-Accel-Redirect应用场景?
nginx 使用 X-Accel-Redirect 实现静态文件下载的统计、鉴权、防盗链、限速
X-Accel系列头
③??proxy_pass_request_body
功能:是否将'客户端请求体'发送给'代理'服务器

④? proxy_pass_request_headers

proxy_force_ranges应用场景?

六? ? ssl相关的
?????proxy_ssl_certificate ?????proxy_ssl_certificate_key ?????proxy_ssl_ciphers ?????proxy_ssl_conf_command ?????proxy_ssl_crl ?????proxy_ssl_name ?????proxy_ssl_password_file ?????proxy_ssl_protocols ?????proxy_ssl_server_name ?????proxy_ssl_session_reuse ?????proxy_ssl_trusted_certificate ?????proxy_ssl_verify ?????proxy_ssl_verify_depth
七? ? 其它常用的
①?? ? ?proxy_http_version
1) 文件的下载涉及到使用'分块传递',但http1.0'不支持'
2) 长连接配置-->'http1.0 短连接'有'大量的TIME_WAIT'
proxy_http_version 1.1;
proxy_set_header Connection "";
注意点:原始请求是'长连接'或者'分块传递',记得加上http1.1的参数
细节:局部设置'proxy_set_header'会覆盖'上层'的'proxy_set_header',避免只设置'Connection',导致报错
3) nginx 'websocket配置' 配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
nginx支持websocket配置

upstream sent invalid chunked response while reading upstream?

Transfer-encoding???chunked? 分块编码传输
②??????proxy_ignore_client_abort
效果: 499报错'变为'200
细节点: 大量'偶现'499,一定要'优化'请求链路

?499报错与proxy_ignore_client_abort? 499报错

③????proxy_ignore_headers
思考:proxy_hide_header 和proxy_ignore_headers的'区别'

④? ? 了解 ?????proxy_intercept_errors ?????proxy_limit_rate ?????proxy_max_temp_file_size? ? ?
? ? ?proxy_store ?????proxy_store_access ?????proxy_temp_file_write_size ?????proxy_temp_path
?????proxy_method
用于设置nginx服务器"请求"代理服务器'使用的请求方法',设置了这个,"客户端的请求方法"将会被'忽略'
?????proxy_next_upstream ?????proxy_next_upstream_timeout ?????proxy_next_upstream_tries
? ? ?proxy_request_buffering

? ? ?proxy_redirect? 重点? 案例参考

HTTP重定向?


++++++++++ 将被代理服务器发出的'重定向'http协议的location改为https协议 ++++++++++
?

? ? ?proxy_set_body ?????proxy_set_header
参考
反向代理与nginx代理模块

proxy_read_timeout时间设置为30s,相当于nginx会等待30s的时间来获得请求的响应,如果在30s内 如果响应接收不完,就会报出来504 timeout
++++++++++++? 分割线??++++++++++++
set_real_ip_from? -->哪个模块提供的指令
--with-http_realip_module
+++++++++ '分割线' +++++++++
++将日志输出到'黑洞'++
error_log /dev/null crit;
++'避免健康冲突配置(原生和第三方)'++
upstream backend {
server 172.25.2.100 max_fails=0 fail_timeout=0;
server 172.25.2.100 down; # 维修中
check interval=2000 rise=1 fall=3 timeout=3000 type=tcp;
}
CDN的一些思考-->客户端真实ip
|