安装过程: 环境: centos7, openresty 使用certbot 生成证书 yum install epel-release -y && yum update -y yum install -y openresty certbot gettext 设置 openresty/nginx 80 端口 server { listen 80; server_name _; location ^~ /.well-known/acme-challenge/ { index index.html index.htm; root html; } location = /.well-known/acme-challenge/ { return 404; } } 重启 nginx/openresty, 执行 certbot certonly -m ${自己的邮箱} --webroot -d ${域名} -w ${ngx www 路径目录} --agree-tos > /tmp/cert.log openssl dhparam 2048 -out dhparam.
local module = {}; module.xxx = xxx; functionn module.xxx () -- todo end return module; Lua 模块被 require 之后, 只会运行一次并进行缓存
安装 LuaRocks, 参考openresty 官方 wget http://luarocks.org/releases/luarocks-2.0.13.tar.gz tar -xzvf luarocks-2.0.13.tar.gz cd luarocks-2.0.13/ ./configure --prefix=/usr/local/openresty/luajit \ --with-lua=/usr/local/openresty/luajit/ \ --lua-suffix=jit \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 make sudo make install 安装 lua2go sudo /usr/local/openresty/luajit/luarocks install --server=https://luarocks.org/dev lua2go 通过 lua2go 调用 golang dll local lua2go = require('lua2go') local xxx = lua2go.Load('./xxx.so') lua2go.Externs([ extern char* captcha(xxx) ]) 试用这个ffi 模块,可能多次调用 lua2go.Externs 函数,导致内存泄漏;最好包装成lua module
安装 LuaRocks, 参考openresty 官方 wget http://luarocks.org/releases/luarocks-2.0.13.tar.gz tar -xzvf luarocks-2.0.13.tar.gz cd luarocks-2.0.13/ ./configure --prefix=/usr/local/openresty/luajit \ --with-lua=/usr/local/openresty/luajit/ \ --lua-suffix=jit \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.
安装过程:
到 maxmind 站点注册个账号 vps 安装 yum install libmaxminddb libmaxminddb-devel perl-Digest-MD5 安装 openresty 第三方包 opm get anjia0532/lua-resty-maxminddb openresty 配置文件, 进行初始化 init_by_lua_block { local geo = require 'resty.maxminddb' if not geo.initted() then geo.init("$GeoLite2.mmdb 路径") end } 可以在其他的 lua 执行节点使用 local geo = require 'resty.maxminddb' local res, err = geo.lookup($ip) 免费库精准度一般; 测试发现很大的误差·······
njs 是可以 javascrip 编写 nginx 处理逻辑。
njs 可以通过编译成 dynamic module 添加到 nginx/openresty ;
编译的过程:
到 http://hg.nginx.org/njs 下载 njs 代码; 进入 nginx/openrety 的源码目录 ./configurate --add-dynamical-module=/xxxx/njs_root_path/nginx ,参数为 njs 源码目录下的 nginx 目录的绝对路径 在 nginx/openresty 源码根路径下执行 make 第4步执行完后, 执行 make install 在 nginx.conf 下配置 njs 动态模块; nginx.conf worker_processes 1; load_module /usr/local/openresty/nginx/modules/ngx_http_js_module.so; # openrety 默认路径 events { worker_connections 1024; } http { js_include http.js; server { listen 80; error_log /usr/local/openresty/nginx/logs/e.log; location / { js_content foo; } } } /usr/local/openresty/nginx/conf/http.
