NGINX+Lua 环境配置

一、环境装备

[root@web01 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core) YUM下载安装相关依赖环境
[root@web01 ~]# yum install gcc gcc-c++ prce prce-devel \
> autoconf make automake \
> openssl-devel openssl zlib-devel zlib \
> httpd-tools gperftools -y 创建下载目录
[root@web01 ~]# cd /opt/;mkdir download 下载相关软件
v2.1-20210510.tar.gz #不要下载官网的,要去下载openresty的优化版本 后面会说出现的坑
lua-nginx-module-0.10.20.tar.gz # 0.10.16 以后都需要3,4两个包
lua-resty-core-0.1.22.tar.gz [必须]
lua-resty-lrucache-0.10.tar.gz [必须]
nginx-1.17.5.tar.gz
ngx_devel_kit-0.3.1.tar.gz 对应下载的网站:https://github.com/openresty
luajit: wget --no-check-certificate https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20210510.tar.gz
lua-nginx-module:wget --no-check-certificate https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.20.tar.gz
lua-resty-core:wget --no-check-certificate https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.22.tar.gz
lua-resty-lrucache:wget --no-check-certificate https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.11.tar.gz
nginx-1.17.5:wget --no-check-certificate http://nginx.org/download/nginx-1.17.5.tar.gz
ngx_devel_kit-0.3.1:wget --no-check-certificate https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.1.tar.gz

二、解压安装相应的软件

[root@web01 /opt/download]# ls *.tar.gz | xargs -n1 tar xzvf
[root@web01 /opt/download]# cd luajit2-2.1-20210510
make install PREFIX=/usr/local/LuaJIT
添加环境变量
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1
[root@web01 /opt/download]# tail -3f /etc/profile
#Lua
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1 安装Lua核心库
lua-resty-core-0.1.21.tar.gz [必须]
lua-resty-lrucache-0.11.tar.gz [必须] 安装在同一个目录下
cd lua-resty-core-0.1.22
make install PREFIX=/usr/local/lua_core
cd ../lua-resty-lrucache-0.11
make install PREFIX=/usr/local/lua_core 编译安装NGINX
[root@web01 /opt/download]# cd nginx-1.17.2/
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--user=nginx --group=nginx \
--with-compat --with-debug --with-file-aio \
--with-google_perftools_module \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_mp4_module \
--with-http_perl_module=dynamic \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module --with-http_xslt_module=dynamic \
--with-mail=dynamic --with-mail_ssl_module \
--with-pcre --with-pcre-jit \
--with-stream=dynamic --with-stream_ssl_module \
--with-stream_ssl_preread_module --with-threads \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' \
--with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' \
--add-module=/opt/download/ngx_devel_kit-0.3.1 \
--add-module=/opt/download/lua-nginx-module-0.10.20 加载lua库,加入到ld.so.conf文件
[root@web01 ~]# cat /etc/ld.so.conf.d/libc.conf
/usr/local/lib
/usr/local/LuaJIT/lib
[root@web01 ~]# ldconfig

测试Lua环境

主配置文件添加如下:nginx.conf
添加在http模块下
# 指定lua模块路径,多个之间";"分隔,其中";;"表示默认搜索路径,默认到nginx的根目录下找
lua_package_path "/usr/local/Lua_core/lib/lua/?.lua;;";
#指定server配置文件目录
include /etc/nginx/conf.d/*.conf; server配置如下
[root@web01 /etc/nginx/conf.d]# cat test_lua.conf
server {
listen 80;
server_name 10.4.7.8 www.server1.com; location /lua {
set $test "hello,world";
content_by_lua '
ngx.header.content_type="text/plain"
ngx.say(ngx.var.test)'; } }

上面都是经过安装的一些坑之后安装完成的,下面是安装过程中出现的坑

坑一:

nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
# 让我不要用这个luajit版本,可以用openresty提供的luajit优化版本,或者干脆直接用openresty
卸载luajit官网版本,下载openresty提供的luajit优化版本

坑二:

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: module 'resty.core' not found:
no field package.preload['resty.core']
no file '../lua-resty-core/lib/resty/core.lua'
no file '../lua-resty-lrucache/lib/resty/core.lua'
no file './resty/core.lua'
no file '/usr/local/LuaJIT/share/luajit-2.0.5/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file '/usr/local/LuaJIT/share/lua/5.1/resty/core.lua'
no file '/usr/local/LuaJIT/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/LuaJIT/lib/lua/5.1/resty/core.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/LuaJIT/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /etc/nginx/nginx.conf:117
网上查找的结果是说
这个问题到git上面看了 ,https://github.com/openresty/lua-nginx-module/issues/1509
就是在nginx.conf 中的 http{}模块中加入下面这行代码:lua_load_resty_core off;但是检查的时候发现这命令已经废弃

按照上面说安装lua-resty-core和依赖文件lua-resty-lrucache解决问题

lua-resty-core-0.1.22.tar.gz
lua-resty-lrucache-0.10.tar.gz

最新文章

  1. 【转】安装mysql 出现:Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
  2. [Notes] Timer Comparision when turn influence computing on/off
  3. Android custom View AirConditionerView hacking
  4. [LeetCode] Missing Number (A New Questions Added Today)
  5. C# 之 System.Diagnostics.Process.Start的妙用
  6. Tomcat就是个容器,一种软件
  7. 编写Qt Designer自定义控件(一)——如何创建并使用Qt自定义控件
  8. GDI画验证码
  9. hdoj 5461 Largest Point
  10. Delphi 调试WEBService程序(ISAPI或CGI) 把Web App Debugger executable转换成 ISAPI/NSAPI
  11. 理解i-node
  12. svm中的数学和算法
  13. Codeforces Round #429 (Div. 2) 补题
  14. vue安装使用
  15. 三种方法实现Hadoop(MapReduce)全局排序(1)
  16. Nginx技术研究系列2-基于Redis实现动态路由
  17. Emmet 语法介绍
  18. 数据库-mysql数据类型
  19. ubuntu 中数据的迁移
  20. 20155311高梓云补交的Mypc课下实践

热门文章

  1. uniapp 小程序自定义组件样式穿透问题
  2. MyBatis_07(动态SQL)
  3. 如何用python脚本采集某网图片
  4. uniapp打包app出现HTML5+ Runtime
  5. (转载)史上最详细的docker学习手册
  6. XSS - Cross Site Scripting
  7. 吴恩达老师机器学习课程chapter06——支持向量机与核函数
  8. 两个DIV的切换
  9. vite vue插件打包配置
  10. vue clickoutside 点击元素以外的区域隐藏该元素