Centos 下安装 nginx+lua openResty 环境

参考安装地址:

http://openresty.org/cn/installation.html

1. 下载 openresty 源码包

如需请先安装依赖:yum install readline-devel pcre-devel openssl-devel gcc

wget https://openresty.org/download/openresty-1.13.6.2.tar.gz

Centos 下安装 nginx+lua openResty 环境

2.  解压缩安装(将其安装到 --prefix 指定的 /opt/openresty 文件夹下,不指定则会默认到 /usr/local/openresty )

tar -zxvf https://openresty.org/download/openresty-1.13.6.2.tar.gz

cd openresty-1.13.6.2

./configure --with-cc-opt="-I/usr/local/include" --with-ld-opt="-L/usr/local/lib" --prefix=/opt/openresty 

make

make install

3.  启动 nginx 并测试 lua

cd /opt/openresty

ls

可以查看到相关文件夹:

Centos 下安装 nginx+lua openResty 环境

启动:

/opt/openresty/nginx/sbin/nginx -c /opt/openresty/nginx/conf/nginx.conf -p /opt/openresty/nginx/

查看启动的 nginx:

ps aux|grep nginx

Centos 下安装 nginx+lua openResty 环境

可以看到 nginx 已经启动成功了,如果原系统已经有运行的 nginx,只需改动 nginx 的配置端口即可,不影响原 nginx

vim /opt/openresty/nginx/conf/nginx.conf

将端口改成未被占用的任意端口, 如下的 8099

添加测试 location 后保存 nginx.conf:

location /lua {
            set $test "hello, world. i love lua";
            content_by_lua '
                ngx.header.content_type = "text/plain";
                ngx.say(ngx.var.test);
            ';
        }

Centos 下安装 nginx+lua openResty 环境

重新启动:

/opt/openresty/nginx/sbin/nginx -s stop

/opt/openresty/nginx/sbin/nginx -c /opt/openresty/nginx/conf/nginx.conf -p /opt/openresty/nginx/

测试访问:

curl http://localhost:8099/lua

Centos 下安装 nginx+lua openResty 环境