环境部署--nginx编译安装lua模块

一、为什么需要安装Lua?
尽管Nginx官方自带的核心模块外加第三方的模块能够满足我们大部分的业务需要,但是业务需求、业务场景变化需要添加些额外的功能,自己去开发一个nginx模块相对来说比较笨重,我们可以使用lua脚本直接内嵌到nginx当中实现一些业务逻辑,完成一些特殊的功能需求。

二、安装lua模块

1、编译安装
下载地址 https://github.com/openresty/luajit2 当前下载的是v2.1版本

git clone https://github.com/openresty/luajit2.git
tar -zxvf v2.1-20200102.tar.gz
cd  luajit2-2.1-20200102
make install PREFIX=/usr/local

2、添加环境变量

vim /etc/profile
#最后两行添加如下内容:
export LUAJIT_LIB=/usr/local/luajit2/lib
export LUAJIT_INC=/usr/local/luajit2/include/luajit-2.1

未添加环境变量将会报错:

./configure: error: ngx_http_lua_module requires the Lua or LuaJIT library and LUAJIT_LIB is defined as /usr/local/luajit2/lib and LUAJIT_INC (path for lua.h) /usr/local/luajit2/include/luajit-2.1, but we cannot find LuaJIT there.

3、下载ngx_devel_kit模块

wget  https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz

NDK(nginx development kit)模块是一个拓展nginx服务器核心功能的模块,第三方模块开发可以基于它来快速实现。 NDK提供函数和宏处理一些基本任务,减轻第三方模块开发的代码量。

4、下载lua-nginx-module模块

wget  https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz

lua-nginx-module模块使nginx中能直接运行lua脚本

5、重新编译nginx源文件
注意:编译需要添加上之前编译的模块并且使用–add_module添加第三方模块;make之后不需要make install;

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_slice_module --with-http_stub_status_module --add-module=../ngx_cache_purge --add-module=/usr/local/src/nginx-upsync-module --add-module=/usr/local/src/ngx_devel_kit-0.3.1 --add-module=/usr/local/src/lua-nginx-module-0.10.14
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Ansible Playbook,用于在目标主机上编译安装Nginx: ``` --- - name: Install Nginx hosts: webserver become: true vars: nginx_version: 1.18.0 tasks: - name: Install prerequisites apt: name: [build-essential, libpcre3-dev, libssl-dev, zlib1g-dev] state: present - name: Download Nginx source get_url: url: "http://nginx.org/download/nginx-{{ nginx_version }}.tar.gz" dest: "/tmp/nginx-{{ nginx_version }}.tar.gz" - name: Extract Nginx source unarchive: src: "/tmp/nginx-{{ nginx_version }}.tar.gz" dest: "/tmp" remote_src: true - name: Configure Nginx shell: "./configure --prefix=/usr/local/nginx --with-http_ssl_module" args: chdir: "/tmp/nginx-{{ nginx_version }}" - name: Build Nginx shell: "make && make install" args: chdir: "/tmp/nginx-{{ nginx_version }}" - name: Start Nginx service: name: nginx state: started ``` 在上面的Playbook中,我们首先定义了一个变量 `nginx_version`,用于指定要安装的Nginx版本。然后,我们使用 `apt`模块安装编译Nginx所需的依赖项。 接下来,我们使用 `get_url`模块从Nginx官网下载了源代码,并使用`unarchive`模块将其解压到 `/tmp`目录中。然后,我们使用 `shell`模块配置和编译了Nginx,并使用`service`模块启动了Nginx服务。 最后,我们可以在命令行中运行以下命令来执行Playbook: ``` ansible-playbook install-nginx.yml ``` 注意,我们假设已经在Ansible中定义了一个名为 `webserver` 的主机组,其中包含要安装Nginx的目标主机。在实际应用中,您可能需要根据自己的环境进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值