NGINX+Lua模块编译安装
时间:2021-08-19
本文章向大家介绍NGINX+Lua模块编译安装,主要包括NGINX+Lua模块编译安装使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
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.19 以后需要必须要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
sudo make install PREFIX=/usr/local/LuaLIB
cd ../lua-resty-lrucache-0.11
sudo make install PREFIX=/usr/local/LuaLIB
编译安装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)';
}
}
-----你努力获得的,都是自己的,不容易忘掉。
星辰和大海都需要门票,诗和远方的路费都很贵。来人间一次,努力成为最好的自己。人间值得,未来可期。
原文地址:https://www.cnblogs.com/woaiyunwei/p/15162913.html
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- redis实战第七篇 使用redis工具(redis-cli)搭建redis cluster
- 使用ROS2机器人操作系统进行多机器人编程技术实践(Multi-Robot Programming Via ROS2 )
- 自动化运维实践 | Ansible playbook重用
- 手把手教你打造高效的 Kubernetes 命令行终端
- docker save load export import的区别
- 使用ABAC控制数据访问
- linux 压力测试工具之ab
- 什么是Python Wheels?为什么要关心它?
- Nginx fastcgi_cache权威指南
- 玩转dockerfile
- redis实战第六篇 手动创建redis cluster
- docker容器入门最佳教程
- redis实战第五篇 jedis 连接 redis sentinel详解
- redis实战第四篇 手动容灾故障转移记录
- 10条很棒的Python一行代码