openresty+lua安装

吴胜涝
2023-12-01

一、下载软件:

下载ngx_openresty-xxx.tar.gz并解压

wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz

ngx_openresty-xxx/bundle目录里存放着nginx核心和很多第三方模块,比如有我们需要的LuaLuaJIT

 

安装LuaJIT

 cd bundle/LuaJIT-2.1-20151219/

make clean && make && make install

ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit

 

下载ngx_cache_purge模块,该模块用于清理nginx缓存

wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz

 

下载nginx_upstream_check_module模块,该模块用于ustream健康检查

wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz

 

二、安装依赖库:

yum install readline-devel pcre-devel openssl-devel perl

 

三、安装ngx_openresty

tar xvf ngx_openresty-1.9.7.1.tar.gz

cd  ngx_openresty-1.9.7.1

mkdir /usr/local/ngx_openresty

编译

./configure --prefix=/usr/local/openresty --with-http_realip_module --with-pcre --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2

 

make && make install

 

--with*** 安装一些内置/集成的模块
--with-http_realip_module 取用户真实ip模块
-with-pcre Perl兼容的达式模块
--with-luajit 集成luajit模块
--add-module 添加自定义的第三方模块,如此次的ngx_che_purge

或:

--prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.7 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre=/opt/pcre-8.40 --with-openssl=/opt/openssl-1.0.1u --with-http_ssl_module

 

 

、配置nginx+lua开发环境
配置及Nginx HttpLuaModule文档在可以查看http://wiki.nginx.org/HttpLuaModule

1、为了方便开发我们在/usr/servers/nginx/conf目录下创建一个lua.conf 
root@user:/home/user# cd /usr/servers/nginx/conf
root@user:/usr/servers/nginx/conf# vim lua.conf
server { 
listen 80; 
server_name _;
#HelloWorld
location /lua { 
default_type 'text/html'; 
content_by_lua 'ngx.say("hello world")'; 
}
}

2、编辑nginx.conf配置文件 
vim /usr/servers/nginx/conf/nginx.conf 
http部分添加如下配置 
lua_package_path "/usr/servers/lualib/?.lua;;"; #lua 模块 
lua_package_cpath "/usr/servers/lualib/?.so;;"; #c模块 
include lua.conf; #单独lua配置

#lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/servers/nginx下找
例如:
http {
include mime.types;
default_type application/octet-stream;
//.....
lua_package_path "/usr/servers/lualib/?.lua;;";
lua_package_cpath "/usr/servers/lualib/?.so;;";
include lua.conf;
}

3、测试是否正常
root@user:/usr/servers/nginx/conf# /usr/servers/nginx/sbin/nginx -t 
如果显示如下内容说明配置成功
nginx: the configuration file /usr/servers/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/servers/nginx/conf/nginx.conf test is successful

4、重启nginx
/usr/servers/nginx/sbin/nginx -s reload

 类似资料: