网站首页 > 技术教程 正文
LUA是近几年被大家所熟悉的一门轻量级语言,它的语言简练,处理效率很高。
Nginx又是一个这些年很火的web代理和中间件服务。
Nginx+LUA被用在很多的应用场景中,就向牛郎遇到织女。
如:
1、Nginx+LUA实现7层防空规则。
2、实现代码的灰度发布
3、实现简单的json接口和数据库交互
等等
那么“幕客”今天先给大家介绍一些基础的内容,就是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使用相关内容,
欢迎关注,幕客将写出更多技术资料!
猜你喜欢
- 2024-10-09 openresty代替nginx并使用lua扩展功能
- 2024-10-09 Redis弱事务性与Lua脚本原子性分析
- 2024-09-08 基于Nginx+lua的蓝绿发布系统(lvs与nginx)
- 2024-09-08 Go Web 框架 Gin 实践17—用 Nginx 部署 Go 应用
- 2024-09-08 一文看懂灰度发布——基于Nginx+Lua+Redis
- 2024-09-08 Lua 基础入门(lua经典详细入门教程中文pdf)
- 2024-09-08 Redis中使用Lua脚本来实现并发下的原子操作
- 2024-09-08 运维篇—基于Nginx+Lua实现的灰度发布
- 2024-09-08 Nginx+Lua+Redis实现高性能缓存数据读取
- 2024-09-08 OpenResty实战-Lua入门-Lua模块(openresty教程)
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)