目录
nginx高速缓存
NGINX高速缓存是一种快速的Web服务器和反向代理服务器,它可以在服务器和客户端之间缓存静态内容,以减少服务器响应时间和减轻服务器的负载。当客户端请求静态内容时,NGINX可以从内存或磁盘缓存中直接返回内容,而不需要向后端服务器请求数据,从而大大缩短响应时间。此外,NGINX还支持CDN(内容分发网络),它可以将缓存内容分发到全球各个节点,以提供更快的访问速度和更好的用户体验。
openresty部署
OpenResty是一个基于Nginx的可扩展Web平台,它集成了许多常用的第三方模块,可以通过编写Lua脚本来扩展Nginx的功能。OpenResty的最大优点是可以使用Lua语言来扩展Nginx,使得开发者可以使用Lua语言来编写高性能的Web应用。
首先停止nginx服务,避免端口冲突
配置yum源
curl https://openresty.org/package/rhel/openresty.repo -o /etc/yum.repos.d/openresty.repo
yum install -y openresty
cd /usr/local/openresty/nginx/conf
cp /usr/local/nginx/conf/nginx.conf .
cp /usr/local/nginx/conf/cert.pem .
检测语法,启动openresty
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx
访问
nginx配置高效缓存
拷贝测试页面
cd /usr/local/openresty/nginx/html/
cp /usr/local/nginx/html/index.php .
cp /usr/local/nginx/html/example.php .
vim /usr/local/nginx/conf/nginx.conf
upstream memcache {
server 127.0.0.1:11211;
keepalive 512;
}
location /memc {
internal;
memc_connect_timeout 100ms; //与memcached服务器进行连接的超时时间
memc_send_timeout 100ms; //与memcached服务器进行发送的超时时间
memc_read_timeout 100ms; //与memcached服务器进行读取数据的超时时间
set $memc_key $query_string; //set指令用于设置变量,$query_string是用于存储请求的查询参数$memc_key变量将被设置为查询字符串
set $memc_exptime 300; //变量过期时间,即缓存有效时间
memc_pass memcache; //缓存服务器地址
}
location ~ \.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;
}
检测语法并重启
测试
ab -c10 -n1000 http://192.168.81.132/index.php