烂笔头

不积跬步无以至千里

0%

使用openresty部署nginx+lua(未整理)

安装依赖

1
yum install pcre-devel openssl-devel gcc curl
1
2
3
cd perl-5.32.0/ #需要安装perl
./Configure -des -Dprefix=/usr/local/perl
make && make install

安装openresty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
tar zxvf openresty-1.17.8.2.tar.gz
cd openresty-1.17.8.2/bundle
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
tar zxvf ngx_cache_purge-2.3.tar.gz
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
cd nginx-1.17.8
patch -p1 < /data/openresty-1.17.8.2/bundle/nginx_upstream_check_module/check_1.16.1+.patch
cd ../../
./configure --with-luajit --with-pcre --with-http_realip_module --add-module=./bundle/nginx_upstream_check_module/ --add-module=./bundle/ngx_cache_purge-2.3 -j2
make && make install
cd /usr/local/openresty/
nginx/sbin/nginx -v
nginx/sbin/nginx # 启动NG

nginx中配置lua

1
vim nginx/conf/nginx.conf

在http部分增加

1
2
lua_package_path "/usr/local/openresty/lualib/?.lua;;";
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";

编写lua脚本测试

1
2
3
4
5
6
7
8
9
server{
listen 80;
server_name _;
location /lua{
default_type text/html;
charset utf-8;
content_by_lua 'ngx.say("hello lua")';
}
}

将lua脚本include到/path/nginx/conf/nginx.conf中,然后reload nginx 就可以访问