查看“Ngx lua”的源代码
←
Ngx lua
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==基础知识== luajit 环境,luajit 类似于 java 的 jit,即即时编译,lua 是一种解释语言,通过 luajit 可以即时编译 lua 代码到机器代码,得到很好的性能; ==1.下载安装LuaJIT== <pre> wget -c http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar xvf LuaJIT-2.0.5.tar.gz && cd LuaJIT-2.0.5 make -j3 && make install</pre> 实在不行直接下载 luajit-2.0.4-3.el6.x86_64.rpm https://www.rpmfind.net/linux/RPM/epel/6/x86_64/luajit-2.0.4-3.el6.x86_64.html ==2. 下载准备nginx lua模块== <pre> wget -c https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz tar xvf v0.10.8.tar.gz lua-nginx-module-0.10.8 https://github.com/openresty/lua-nginx-module/tags </pre> ==3.ngx_devel_kit== <pre> wget -c https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz ngx_devel_kit-0.3.0 </pre> ==4. nginx build == <pre> #//先导入环境变量,告诉nginx去哪里找luajit export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0 ./configure --prefix=/usr/local/nginx-1.4.2 --with-ld-opt="-Wl,-rpath,/usr/local/lib" --add-module=../lua-nginx-module-0.8.6 --add-module=../ngx_devel_kit-0.3.0 ./configure --prefix=/usr/local/nginx-1.4.2 --with-ld-opt="/path/to/luajit-or-lua/lib" --add-module=../lua-nginx-module-0.8.6 --add-module=../ngx_devel_kit-0.3.0 # make -j2 # make install --add-module=/root/rpmbuild/SOURCES/lua-nginx-module-0.10.8/ --add-module=/root/rpmbuild/SOURCES/ngx_devel_kit-0.3.0 /root/rpmbuild/SOURCES/ngx_devel_kit-0.3.0 ./configure: error: invalid option "--without-mail_pop4_module" --with-ld-opt=parameters —设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:--with-ld-opt="-L /usr/local/lib". # or tell where to find Lua if using Lua instead: #export LUA_LIB=/path/to/lua/lib #export LUA_INC=/path/to/lua/include # Here we assume Nginx is to be installed under /opt/nginx/. ./configure --prefix=/opt/nginx \ --with-ld-opt="-Wl,-rpath,/path/to/luajit-or-lua/lib" \ --add-module=/path/to/ngx_devel_kit \ --add-module=/path/to/lua-nginx-module # Note that you may also want to add `./configure` options which are used in your # current nginx build. # You can get usually those options using command nginx -V # you can change the parallism number 2 below to fit the number of spare CPU cores in your # machine. make -j2 make install </pre> ==5. nginx lua配置== <pre> nginx配置文件加入如下配置: location ~* ^/2328(/.*) { default_type 'text/plain'; content_by_lua 'ngx.say("hello, ttlsa lua")'; } 5. 启动测试 5.1 启动nginx # curl http://test.ttlsa.com/2328/ hello, ttlsa lua //使用curl测试 </pre> ==trouble shooting== <pre> + /usr/bin/install -m 644 -p /root/rpmbuild/SOURCES/logrotate /root/rpmbuild/BUILDROOT/ops_nginx-1.8.1-2.x86_64/etc/logrotate.d/nginx + /usr/lib/rpm/find-debuginfo.sh --strict-build-id /root/rpmbuild/BUILD/nginx-1.8.1 extracting debug info from /root/rpmbuild/BUILDROOT/ops_nginx-1.8.1-2.x86_64/data/apps/nginx/sbin/nginx /usr/lib/rpm/debugedit: canonicalization unexpectedly shrank by one character error: Bad exit status from /var/tmp/rpm-tmp.osP0DB (%install) RPM build errors: Bad exit status from /var/tmp/rpm-tmp.osP0DB (%install) --add-module=/root/rpmbuild/SOURCES/ngx_devel_kit-0.3.0/ ==> --add-module=/root/rpmbuild/SOURCES/ngx_devel_kit-0.3.0 关于下面这个问题 直接 下载 luajit-2.0.4-3.el6.x86_64.rpm https://www.rpmfind.net/linux/RPM/epel/6/x86_64/luajit-2.0.4-3.el6.x86_64.html [root@centos evan]# rpm -ivh ops_nginx-1.8.1-2.x86_64.rpm error: Failed dependencies: libluajit-5.1.so.2()(64bit) is needed by ops_nginx-1.8.1-2.x86_64 ln -s /usr/local/lib/libluajit-5.1.so.2.0.5 /lib64/libluajit-5.1.so.2 这个问题很多人发现后采用了将libluajit-5.1.so.2链接到系统库的做法,比如http://cywhoyi.iteye.com/blog/2118913,以及https://www.ttlsa.com/nginx/nginx-modules-ngx_lua,采用的 ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/ ln -s /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/ ln -s /usr/local/lib/libluajit-5.1.so.2 /usr/lib64/lua/5.1/ ln -s /usr/local/lib/libluajit-5.1.so.2 /usr/lib/ [root@rpmbuild ~]# file /lib/libluajit-5.1.so.2 /lib/libluajit-5.1.so.2: broken symbolic link to `/usr/local/luajit/lib/libluajit-5.1.so.2' [root@rpmbuild ~]# file /usr/local/luajit/lib/libluajit-5.1.so.2 /usr/local/luajit/lib/libluajit-5.1.so.2: cannot open `/usr/local/luajit/lib/libluajit-5.1.so.2' (No such file or directory) 是因为系统默认会到/usr/lib或/usr/lib64找libluajit-5.1.so.2,因为不存在,所以找不到。 可以将文件拷贝至/usr/lib和/usr/lib64中,如下: cp libluajit-5.1.so.2.0.1 /usr/lib/libluajit-5.1.so cp libluajit-5.1.so.2.0.1 /usr/lib/libluajit-5.1.so.2 cp libluajit-5.1.so.2.0.1 /usr/lib64/libluajit-5.1.so.2 cp libluajit-5.1.so.2.0.1 /usr/lib64/libluajit-5.1.so 再次尝试命令:/home/tengine/sbin/nginx -v 结果: Tengine version: Tengine/1.4.3 (nginx/1.2.5) 安装成功</pre> ==参考资料== [http://dwlinux.blog.51cto.com/3898592/1381231 Nginx安装] [[category:nginx]]
返回至
Ngx lua
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
我的导航
关于我
shell
python
ops
linuxchina.net
blog.linuxchina
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息