[幕客技术]Nginx+LUA开发板块编译方式及测试

作者 : 开心源码 本文共2968个字,预计阅读时间需要8分钟 发布时间: 2022-05-12 共169人阅读

LUA是近几年被大家所熟习的一门轻量级语言,它的语言简练,解决效率很高。

Nginx又是一个这些年很火的web代理商和中间件服务。

Nginx+LUA被用在很多的应用场景中,就向牛郎遇到织女。

如:

1、Nginx+LUA实现7层防空规则。

2、实现代码的灰度发布

3、实现简单的json接口和数据库交互

等等

[幕客技术]Nginx+LUA开发板块编译方式及测试

那么“幕客”今天先给大家详情少量基础的内容,就是Nginx+LUA的安装

一、安装LUA环境及相关库

官方网站:https://github.com/openresty/lua-nginx-module

1、LuaJIT

下载LUA库

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz

make install PREFIX=/usr/local/LuaJIT

export LUAJIT_LIB=/usr/local/LuaJIT/lib

export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0

3、ngx_devel_kit和lua-nginx-module

下载支持LUA的nginx 板块

cd /opt/download

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz

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

分别解压

4、编译安装

重点是在原来编译参数的基础上,加入如下:

–add-module=/opt/download/ngx_devel_kit-0.3.0 –add-module=/opt/download/lua-nginx-module-0.10.9rc7

编译如下:

./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 –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-compat –with-file-aio –with-threads –with-http_addition_module –with-http_auth_request_module –with-http_dav_module –with-http_flv_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp4_module –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-mail –with-mail_ssl_module –with-stream –with-stream_realip_module –with-stream_ssl_module –with-stream_ssl_preread_module –with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' –with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' –add-module=/opt/download/ngx_devel_kit-0.3.0 –add-module=/opt/download/lua-nginx-module-0.10.9rc7

make -j 4 && make install

二、测试

1、通过nginx -V命令测试能否编译

如下:

# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-http_gunzip_module --with-stream_realip_module --with-http_realip_module --add-module=/root/ngx_devel_kit-0.3.0 --add-module=/root/lua-nginx-module-0.10.9rc7

2、配置测试

配置nginx.conf下server一级下的 lua

server {

location /echo_imoocc {

default_type 'text/html';

content_by_lua 'ngx.say(“Hello,imoocc”)';

}

}

打开浏览器,访问地址:

[幕客技术]Nginx+LUA开发板块编译方式及测试

出现如上页面,说明编译成功了!

大家明白了吗,后续幕客将不断推出更多Nginx、LUA使用相关内容,

欢迎关注,幕客将写出更多技术资料!

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » [幕客技术]Nginx+LUA开发板块编译方式及测试

发表回复