含义及理解:
OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。
其目标是让Web服务直接跑在Nginx服务内部,充分利用Nginx的非阻塞I/O模型,不仅仅对HTTP客户端请求,甚至于对远程后端诸如MYSQL,PostgreSQL,Memcached以及Redis等都进行一致的高性能响应
实验搭建
首先关闭nginx服务(其自身已经有nginx,所以需要把nginx关闭)
nginx -s stop
解压编译安装
tar zxf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
./configure --prefix=/usr/local/openresty
gmake && gmake install
拷贝之前example.php和index.php到默认发布目录准备测试
cd /usr/local/openresty/nginx/html
cp /usr/local/lnmp/nginx/html/index.php .
cp /usr/local/lnmp/nginx/html/example.php .
修改openresty的nginx配置文件
vim /usr/local/openresty/nginx/conf/nginx.conf
upstream memcache {
server localhost:11211;
keepalive 512;
}
location /memc {
internal; # 只接收内部访问,不接受外部http访问。比较安全
memc_connect_timeout 100ms;
memc_send_timeout 100ms; ##后端服务器数据回传时间
memc_read_timeout 100ms; ##连接成功后,后端服务器响应时间
set $memc_key $query_string;
set $memc_exptime 300;
memc_pass memcache;
}
location ~ \.php$ {
set $key $uri$args;
##http的GET方法表示get、PUT方法表示set
srcache_fetch GET /memc $key;(这两个配置的作用是:请求php页面时,先会去memcache中找,如果没有,正常访问;
srcache_store PUT /memc $key; 访问结束后将结果存到memcache,下次访问时直接从缓存中)
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
编写配置完毕检测语法并开启nginx
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx
再次对网页进行压力测试:
ab -c 10 -n 5000 http://172.25.11.4/index.php
ab -c 10 -n 5000 http://172.25.11.4/example.php
与之前只设定了php的memcache的网页进行对比
发现速度会比之前只加了php的缓存更快
重点说明一下对index.php页面的访问,访问速度有了明显的差别 因为php是没有缓存的