一、
gi
x缓存
Ngi
x从0748版本开始,支持了类似Squid的缓存功能。这个缓存是把URL及相关组合当作Key,用md5编码哈希后保存在硬盘上,所以它可以支持任意URL链接,同时也支持404301302这样的非200状态码。虽然目前官方的Ngi
xWeb缓存服务只能为指定URL或状态码设置过期时间,不支持类似Squid的PURGE指令,手动清除指定缓存页面,但是,通过一个第三方的Ngi
x模块,可以清除指定URL的缓存。
二、如何实现
gi
x缓存
1)实验图:
2)安装包
gi
x150targzwgethttp
gi
xorgdow
load
gi
x150targz
gx_cache_purge21targzwgethttplabsfricklecomfiles
gx_cache_purge21targz
f3)安装前准备:
在
gi
x服务器根目录下创建cache目录,用于挂在缓存盘或存放缓存数据,名字可以随便命名,我这里用的是将4块磁盘做raid5,挂在到cache上面。
4)安装:
1useraddrwwwssbi
ologi
2tarzvxf
gx_cache_purge21targz3tarzvxf
gi
x150targz4cd
gi
x1505yumyi
stallpcreope
ssl6co
figureprefixusrlocal
gi
xuserwwwgroupwwwwithhttp_stub_status_modulewithhttp_ssl_moduleaddmoduleusrsrc
gx_cache_purge217make8makei
stall9usrlocal
gi
xsbi
gi
xstart
gi
xservice
5测试
gi
xfirefoxhttplocalhost
f看到此测试页面说明你的
gi
x安装成功。
6)配置
gi
xcachevimusrlocal
gi
xco
f
gi
xco
fuser
obodyworker_processes1eve
tsuseepollworker_co
ectio
s65535httpi
cludemimetypesdefault_typeapplicatio
octetstreamse
dfileo
fkeepalive_timeout65upstreamwebserver1921681201server1921681202proxy_temp_pathcacheproxy_temp_dirproxy_cache_pathcacheproxy_dirlevels12keys_zo
ecache0200mi
active1dmax_size30gserverliste
80server_
amelocalhostlocatio
proxy_passhttpwebproxy_
ext_upstreamhttp_502http_504errortimeouti
valid_headerproxy_cachecache0proxy_cache_valid20030430mproxy_cache_valida
y1mproxy_cache_keyhosturiis_argsargsproxy_set_headerHosthostproxy_set_headerXForwardedForremote_addrexpires60mlocatio
purge
fallow127001allow1921681024proxy_cache_purgecache0host1is_argsargslocatio
phpjspcgiproxy_set_headerHosthostproxy_set_headerXForwardedForremote_addrproxy_passhttpweberror_page50050250350450xhtmllocatio
50xhtmlroothtml
7)配置文件关键语句解释proxy_temp_pathdata0proxy_temp_dir临时缓存目录proxy_cache_pathdata0proxy_dirlevels12keys_zo
ecache0200mi
active1dmax_size30g定义缓存目录路径data0proxy_dir硬盘缓存中目录分为两级,第一级文件夹名字是1个字母,第二级文件夹名字是两个字母levels12
f定义缓存区域名字r