Nginx与Lua的开发

1. Lua基础语法

安装lua

hello world

也可以编写lua脚本

运行脚本

lua注释

变量

局部变量的话前面加个local

循环

if语句

2. Nginx与Lua开发环境

https://www.imooc.com/article/19597

Nginx编译安装Lua模块

一、安装LUA环境及相关库

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

1、LuaJIT

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

2、ngx_devel_kit和lua-nginx-module

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

分别解压、安装

3、重新编译编译Nginx
cd /opt/download
wget http://nginx.org/download/nginx-1.12.1.tar.gz
执行解压,后按照如下方式编译:

./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

4、加载lua库,加入到ld.so.conf文件
echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf
然后执行如下命令:
ldconfig

原文地址:https://www.cnblogs.com/tangzhe/p/9533682.html

时间: 2024-08-02 17:00:28

Nginx与Lua的开发的相关文章

使用Nginx+Lua(OpenResty)开发高性能Web应用

在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等场景:而把Nginx作为一个Web容器使用的还不是那么广泛.Nginx的高性能是大家公认的,而Nginx开发主要是以C/C++模块的形式进行,整体学习和开发成本偏高:如果有一种简单的语言来实现Web应用的开发,那么Nginx绝对是把好的瑞士军刀:目前Nginx团队也开始意识到这个问题,开发了nginxScript:可以在Nginx中使用JavaScript进行动态配置一些变量和动态脚本执行:而目前市面上

Nginx+Lua(OpenResty)开发高性能Web应用

使用Nginx+Lua(OpenResty)开发高性能Web应用 博客分类: 跟我学Nginx+Lua开发 架构 ngx_luaopenresty 在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等场景:而把Nginx作为一个Web容器使用的还不是那么广泛.Nginx的高性能是大家公认的,而Nginx开发主要是以C/C++模块的形式进行,整体学习和开发成本偏高:如果有一种简单的语言来实现Web应用的开发,那么Nginx绝对是把好的瑞士军刀:目前Ngin

nginx 与 lua 开发环境搭建

首先下载最新版的 相关软件 的安装文件. nginx: http://nginx.org/en/download.html LuaJIT: http://luajit.org/download.html lua-nginx-module: https://github.com/openresty/lua-nginx-module/releases/tag/v0.9.16 ngx_devel_kit: https://github.com/simpl/ngx_devel_kit/releases/

17. Nginx与Lua开发

安装 Lua 和 Lua for nginx #安装lua yum install -y lua lua -v 安装更高效的 Lua 语言解释器 LuaJIT wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz tar -zxvf LuaJIT-2.0.2.tar.gz cd LuaJIT-2.0.2 make install PREFIX=/usr/local/LuaJIT/2.0.2 export LUAJIT_LIB=/usr/local

nginx与Lua执行顺序

Nginx顺序 Nginx 处理每一个用户请求时,都是按照若干个不同阶段(phase)依次处理的,而不是根据配置文件上的顺序. Nginx 处理请求的过程一共划分为 11 个阶段,按照执行顺序依次是 post-read.server-rewrite.find-config.rewrite.post-rewrite. preaccess.access.post-access.try-files.content.log. post-read: 读取请求内容阶段 Nginx读取并解析完请求头之后就立即

[nginx] 由Lua 粘合的Nginx生态环境-- agentzh tech-club.org

[nginx] 由Lua 粘合的Nginx生态环境-- agentzh tech-club.org 演讲听录 [复制链接] kindle LT管理团队 Rank: 9Rank: 9Rank: 9 未绑定新浪微博 签到222 注册时间1970-1-1最后登录2015-6-5在线时间168 小时阅读权限200积分19025帖子119主题35精华2UID9223 LT总司令 LT元老 LT教授 串个门加好友打招呼发消息 电梯直达跳转到指定楼层 1# 发表于 2013-1-12 12:43:47 |只看

nginx中lua脚本输出

在nginx中嵌入lua模块,能够使得nginx服务端的开发大大地方便,尤其是在实现一些额外的统计等小功能的时候.在nginx模块中直接lua嵌入脚本文件,可以直接使用nginx中lua模块的一些函数直接返回数据.可以调用的函数如下:ngx.say(),ngx.print(),return ,ngx.exit()等等,下面介绍一下这些函数的区别: (1)ngx.say()函数是返回该函数的参数加换行的数据,例如ngx.say("hello"),则返回数据hello/r/n, (2)ng

动态扩展Nginx支持Lua功能

一.Lua说明: Lua 是一个简洁.轻量.可扩展的脚本语言,也是号称性能最高的脚本语言,用在很多需要性能的地方,比如:游戏脚本,nginx,wireshark的脚本,当你把他的源码下下来编译后,你会发现解释器居然不到200k,非常变态.很多应用程序使用Lua作为自己的嵌入式脚本语言,以此来实现可配置性.可扩展性. 二.实验环境: 192.168.1.194服务器(centos 6.5 final版本) nginx版本:nginx-1.6.1 三.安装配置: 这里假定已经安装好了nginx(安装

Nginx安装lua支持

Nginx安装lua支持 需要LuaJIT-2.0.4.tar.gz,ngx_devel_kit,lua-nginx-module 1.下载安装LuaJIT-2.0.4.tar.gz wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz tar xzvf LuaJIT-2.0.4.tar.gz cd LuaJIT-2.0.4 make install PREFIX=/usr/local/luajit #注意环境变量! export LUAJ