首页 > 系统相关 >angie nginx_lua 模块使用

angie nginx_lua 模块使用

时间:2023-11-03 16:23:33浏览次数:38  
标签:luarocks lua share nginx usr angie local

angie 包含了不少社区模块,docker 镜像更加方便,都已经安装了,以下是一个测试lua 模式的使用
因为默认官方构建的是一个动态扩展模块,对于三方lua 模块安装不是很方便,我参考了openresty
对于luarocks 的支持,这样我们自己安装三方lua 模块就比较方便的

构建支持luarocks 的dcoker 镜像

为了方便我是直接基于docker 版本的rocky 镜像修改的,直接通过docker 构建已经安装luarocks,其他系统的类似

  • Dcokerfile
    基于luarocks 构建部分我直接复制了openresty 的luajit 目录的文件
 
FROM docker.angie.software/angie:1.3.1-rocky
RUN mkdir -p /run/angie/
# copy from openresty add cjson 
COPY openresy-lua/luajit/ /usr/share/angie/lualib/
COPY luarocks-3.9.2.tar.gz /tmp/luarocks-3.9.2.tar.gz
RUN yum install -y wget gcc unzip  \
   && cd  /tmp/ && tar -zxvf  luarocks-3.9.2.tar.gz \
   && cd luarocks-3.9.2 \
   && ./configure --prefix=/usr/share/angie/lualib/ \
      --with-lua=/usr/share/angie/lualib/ \
      --lua-suffix=jit \
      --with-lua-include=/usr/share/angie/lualib/include/luajit-2.1 \
    && make build \
    && make install \
    && cd /tmp \
    && rm -rf  luarocks-3.9.2.tar.gz luarocks-3.9.2 \
    && ln -s /usr/share/angie/lualib/share/lua/5.1 /usr/share/lua/5.1
# 此处方便找一些c库依赖
ENV LUA_CPATH="/usr/share/angie/lualib/?.so;/usr/share/angie/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/share/angie/lualib/lib/?.so;/usr/local/lib/lua/5.1/loadall.so;/usr/share/angie/lualib/lib/lua/5.1/?.so"

lua 模块开发服务

  • 应用Dockerfile
FROM dalongrong/angie:1.3.1-rocky-luarocks
# 安装了hashids 以及lua-resty-http,基于上边构建好的luarocks
RUN /usr/share/angie/lualib/bin/luarocks install  lua-resty-hashids \
   && /usr/share/angie/lualib/bin/luarocks install lua-resty-http

  • 开启lua 模块
    angie.conf
 
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;
  • location 集成
    angie 默认的default.conf
 
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/angie/html;
        index  index.html index.htm;
    }
    location /status/ {
        api     /status/;
        allow   127.0.0.1;
        deny    all;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/angie/html;
    }
   # cjson hashids 测试
    location /demo {
        default_type text/html;
        content_by_lua_block {
            local cjson = require("cjson")
            local hashids = require("hashids");
            local h = hashids.new("this is my salt")
            local hash = h:encode(1337)
            local conf = {
                name = "dalong",
                age =333,
                id = hash,
            }
            ngx.say(cjson.encode(conf))
        }   
    }
   # http 请求测试
   location = /http {
        default_type text/html;
        content_by_lua_block {
            local httpc = require("resty.http").new()
            -- Single-shot requests use the `request_uri` interface.
            local res, err = httpc:request_uri("http://192.168.254.241:8080/app.json", {
                method = "GET"
            })
            if not res then
                ngx.log(ngx.ERR, "request failed: ", err)
                return
            end
 
            -- At this point, the entire request / response is complete and the connection
            -- will be closed or back on the connection pool.
 
            -- The `res` table contains the expeected `status`, `headers` and `body` fields.
            local status = res.status
            local length = res.headers["Content-Length"]
            local body   = res.body
            ngx.say(body)
        }
    }
}
  • 效果

 

说明

构建好的镜像我已经push dockerhub 了,可以直接使用dalongrong/angie:1.3.1-rocky-luarocks, 目前测试上包查找以及模块功能上与openresty
基本类似,angie 的all-in-one 模式还是挺方便的

参考资料

https://angie.software/en/install/#install-docker
https://github.com/openresty/docker-openresty/blob/master/alpine/Dockerfile.fat
https://github.com/luarocks/luarocks
https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Unix

标签:luarocks,lua,share,nginx,usr,angie,local
From: https://www.cnblogs.com/rongfengliang/p/17807836.html

相关文章

  • nginx 302问题
    nginx抓包显示302访问的ip端口有发生变化踩坑需配置location/abc{proxy_passhttp://192.168.146.64:7118/;proxy_intercept_errorson;#捕捉错误error_page301302307=@handle_redirects;}......
  • 宝塔 nginx 运行 vue项目
    宝塔安装nginxnginx根目录:/www/server/nginx/html修改nginx配置下滑到70多行,添加server对象内容,内容如下server{listen82;server_nametest2;location/{roothtml/test2;indexindex.htmlindex.htm;......
  • 在虚拟机(Linux)中Docker中部署Nginx成功,但是在宿主机无法访问Nginx站点?
    1.问题本文是基于黑马程序员Docker基础--常见命令一课中部署Nginx时遇到的问题作出解答。在虚拟机(Linux)中Docker中部署Nginx成功,但是在宿主机无法访问Nginx站点如图,Nginx服务已经启动成功但是我们在宿主机的浏览器试图访问的时候却总是报错:2.解决思路2.1查看端口号是否映......
  • angie rocky docker 镜像问题
    angierockydocker在构建的时候似乎有一些问题,启动的时候会有问题异常信息angie:[emerg]open()"/run/angie/angie.pid"failed(2:Nosuchfileordirectory)解决方法自己构建一个镜像,对于缺少的文件夹进行创建FROMdocker.angie.software......
  • linux下安装nginx
    下载nginxwgethttps://nginx.org/download/nginx-1.25.3.tar.gzyum安装依赖包yum-yinstallgcczlibzlib-develpcre-developensslopenssl-devel解压tar-zxvfnginx-1.22.0.tar.gz配置当前nginxcdnginx-1.22.0./configure--prefix=/usr/local/nginx......
  • 前后端都用得上的 Nginx 日常使用经验
    前言nginx是一个高性能的开源反向代理服务器和web服务器,一般用来搭建静态资源服务器、负载均衡器、反向代理,本文将分享其在Windows/docker中的使用,使用nssm部署成服务的方案脚本,局域网中自定义域名解决https提示不安全的解决方案,以及一路踩过的坑。特点高性能:事件驱......
  • 启动nginx报错nginx: [emerg] unexpected end of file, expecting "}" in /usr/local/
    启动nginx报错:“nginx:[emerg]unexpectedendoffile,expecting“}”in/usr/local/nginx/conf/nginx.conf:118”重启nginx时,报这么个错:[root@localhostconf]#/usr/local/nginx/sbin/nginx-sreloadnginx:[emerg]unexpectedendoffile,expecting“}”in/usr/lo......
  • nginx coturn socat privoxy opencv 静态编译
    文档说明:只记录关键的地方;发文时间:2023-11-02意义:linux环境,免安装下载后即可使用环境:alpine:3.18dockerclang状态:完善中体验编译结果nginx静态编译关键点nginxusePCRE2libraryonnginx1.21.5hg脚本全称是mercurialopensslzlibpcpre2等静态库......
  • angie vod_module 模块的问题
    上次我简单说过angie官方构建的nginx-vod-module有一些问题,经常测试实际上问题还是不小的主要问题声音处理会有问题同时缩略图似乎也有问题解决方法应该自己构建nginx-vod-module,同时编译为动态模块(包含debug最好)说明实际上通过日志我们也看出了不少警告信息,十实际上......
  • nginx设置允许跨域
    server{listen8088;server_namelocalhost;#charsetkoi8-r;#access_loglogs/host.access.logmain;add_header'Access-Control-Allow-Methods''POST,GET,OPTIONS';add_header......