模拟缓存前移的实现
- 解压openstry包并编译安装
[root@server1 ~]# nginx -s stop
[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz
[root@server1 openresty-1.13.6.1]# ./configure
[root@server1 openresty-1.13.6.1]# gmake && gmake install
- 將memcache用於測試的两个发布页面复制到Openrestry的默认发布目录下
[root@server1 openresty-1.13.6.1]# cd /usr/local/openresty/
- openresty配置文件的编辑
[root@server1 openresty]# pwd
/usr/local/openresty
[root@server1 openresty]# cd nginx
[root@server1 nginx]# vim conf/nginx.conf
17 http {
18 upstream memcache {
19 server localhost:11211;
20 }
71 location /memc {
72 internal;
73 memc_connect_timeout 100ms;
74 memc_send_timeout 100ms;
75 memc_read_timeout 100ms;
76 set $memc_key $query_string;
77 set $memc_exptime 300;
78 memc_pass memcache;
79
80 }
81 location ~ \.php$ {
82 set $key $uri$args;
83 srcache_fetch GET /memc $key;
84 srcache_store PUT /memc $key;
85 root html;
86 fastcgi_pass 127.0.0.1:9000;
87 fastcgi_index index.php;
88 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
89 include fastcgi.conf;
90 }
[root@server1 nginx]# pwd
/usr/local/openresty/nginx
[root@server1 nginx]# cd sbin
[root@server1 sbin]# ./nginx -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 sbin]# ./nginx
-
浏览器查看
若为该页面则正确 -
压力测试
[root@server1 nginx]# ab -c 10 -n 5000 http://172.25.42.1/index.php
[root@server1 nginx]# ab -c 10 -n 5000 http://172.25.42.1/example.php
Openresty在memcache的基础上,再次加快了缓存的速度。