前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx缓存构建 - 乐享诚美

nginx缓存构建 - 乐享诚美

作者头像
司夜
发布2023-10-18 10:31:31
1470
发布2023-10-18 10:31:31
举报
文章被收录于专栏:开发三两事

一级缓存本地缓存实现 二级缓存redis缓存实现 三级缓存nginx缓存实现(80%请求处理在这一层级) openresty安装

命令示例:

代码语言:javascript
复制
yum install -y readline-devel pcre-devel openssl-devel gcc
wget http://openresty.org/download/openresty-1.21.4.1.tar.gz
tar -zxvf openresty-1.21.4.1.tar.gz
cd openresty-1.21.4.1
cd bundle
cd LuaJIT-2.1-20220411
make clean && make && make install
ln -sf luajit-2.1.0-beta3 /usr/local/bin/luajit
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar -zxvf 2.3.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar -zxvf v0.3.0.tar.gz
cd bundle
./configure --prefix=/usr/servers --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundlnginx_upstream_check_module-0.3.0/
make && make install

ngnix+lua 执行lua文件

代码语言:javascript
复制
vim ./lua/test.lua
test.lua文件中插入
ngx.say(" excute lua file successfully! ");
nginx.conf修改
location / {
            #root   html;
            #index  index.html index.htm;
            default_type text/html;
            #content_by_lua_block {
            #    ngx.say("hello, world")
            #}
            content_by_lua_file lua/test.lua;
        }
./sbin/nginx -s reload刷新配置

刷新页面后则显示 excute lua file successfully! 此处可以看到nginx只要请求8080接口返回的就是lua文件了,这里我们可以实现自己的缓存页面已到达nginx缓存目的,将百分之80的请求再此处进行处理,降低服务器压力;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-07-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档