nginx upstream開啟keepalive
upstream?tomcat?{ ?server?ops-coffee.cn:8080; ?keepalive?1024; } server?{ ?location?/?{ ??proxy_http_version?1.1; ??proxy_set_header?Connection?""; ??proxy_pass?http://tomcat; ?} }
nginx在項目中大多數情況下會作為反向代理使用,例如nginx后接tomcat,nginx后接php等,這時我們開啟nginx和后端服務之間的keepalive能夠減少頻繁創建TCP連接造成的資源消耗,配置如上
keepalive: 指定每個nginxworker可以保持的最大連接數量為1024,默認不設置,即nginx作為client時keepalive未生效
proxy_http_version 1.1: 開啟keepalive要求HTTP協議版本為HTTP 1.1
proxy_set_header Connection “”: 為了兼容老的協議以及防止http頭中有Connection close導致的keepalive失效,這里需要及時清掉HTTP頭部的Connection
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END