nginx 安装 lua 模块
1. 系统环境
Centos 7
2. 下载
- nginx: https://github.com/nginx/nginx/archive/release-1.17.9.tar.gz
- nginx lua-nginx-module 模块: https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz
- 依赖: ngx devel kit 模块: https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz
- 依赖: openresty/luajit2 https://github.com/openresty/luajit2/archive/v2.1-20200102.tar.gz
3. 安装
nginx
解压压缩包:
nginx-1.17.9.tar.gz
、ngx_devel_kit-0.3.1.tar.gz
、lua-nginx-module-0.10.14.tar.gz
、luajit2-2.1-20200102.tar.gz
安装
nginx
及nginx 模块
cd luajit2-2.1-20200102
make && make install PREFIX=/usr/local/luajit
cd nignx-1.17.9
# /usr/local/lib64 为 rabbitmq-c 库目录
./configure --prefix=/usr/local/nginx --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --with-http_ssl_module --with-http_stub_status_module --add-module=/home/soft/ngx_devel_kit-0.3.1 --add-module=/home/soft/lua-nginx-module-0.10.14
make && make install
注意点
:
这里lua-nginx-module
使用0.10.14
版本, 如果高于此版本
会出现如下兼容性问题
:
sbin/nginx -c conf/nignx.conf
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: ./resty/core.lua:6: module 'resty.core.regex' not found:
no field package.preload['resty.core.regex']
no file './resty/core/regex.lua'
no file '/usr/local/share/luajit-2.1.0-beta3/resty/core/regex.lua'
no file '/usr/local/share/lua/5.1/resty/core/regex.lua'
no file '/usr/local/share/lua/5.1/resty/core/regex/init.lua'
no file './resty/core/regex.so'
no file '/usr/local/lib/lua/5.1/resty/core/regex.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /usr/local/nginx/conf/nginx.conf:88
4. 配置 nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#log_format dm ' msg::"$request_body"##ua::$http_user_agent##referer::$http_referer##clientIP::$remote_addr##createdAt::$time_iso8601" ';
server {
listen 80;
server_name localhost;
location /lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
#error_page 404 /404.html;
#
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
5. 测试
cd /usr/local/nginx
sbin/nginx -c conf/nginx.conf
curl http://localhost/lua
hello, lua
正文到此结束