OpenResty是由Nginx核心加很多第三方模块组成,实现了openresty作为反向代理从而缓存内容,现在,将memcache缓存模块同样加入Openresty中,减少服务器的访问压力
tar zxf openresty-1.15.8.1.tar.gz 解压安装包
cd openresty-1.15.8.1
./configure 编译
gmake && gmake install 会提示使用gmake安装
nginx -s stop 关闭nginx服务,因为openresty是一个类似于nginx的服务
cd /usr/local/openresty/nginx/html 将用来测试php缓存的时候修改好的example.hph和memcache.php文件拷贝到openresty默认的发布目录下
cp /usr/local/lnmp/nginx/html/memcache.php .
cp /usr/local/lnmp/nginx/html/example.php .
vim /usr/local/openresty/nginx/conf/nginx.conf 编辑openresty的配置文件
http {
upstream memcache {
server localhost:11211; memcache在本机的11211端口
}
location /memc { 增加memcache模块
internal; 只允许内部
memc_connect_timeout 100ms; 定义连接发送以及超时时间
memc_send_timeout 100ms;
memc_read_timeout 100ms;
set $memc_key $query_string; memcache以键值对的形式存储
set $memc_exptime 300;
memc_pass memcache;
}
location ~ \.php$ { php模块
set $key $uri$args;
srcache_fetch GET /memc $key;
srcache_store PUT /memc $key; 设置访问形式
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和php连接时识别的文件
}
/usr/local/openresty/nginx/sbin/nginx 启动服务
浏览器:
http://172.25.38.1/memcache.php 图表查看缓存页面 用户:memcache 密码:redhat
http://172.25.38.1/example.php 测试页面(不断刷新,图表页面会变)
真机测试:
ab -c 10 -n 5000 http://172.25.38.1/index.php 访问时长很短且没有失败,openresty下的缓存速度明显加快
ab -c 10 -n 5000 http://172.25.38.1/example.php 访问时长短且没有失败
版权声明:本文为weixin_45368526原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。