源码安装nginx并配置Lua模块

本文记录了在无法联网的测试机上手动安装nginx 1.2.6及配置Lua模块的过程。涉及下载nginx和lua-nginx-module源码,解决lua库、readline、ncurses依赖问题,以及编译安装过程中遇到的链接错误,最终成功安装但因需使用set指令而需安装rewrite模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天需要在测试机布置nginx测试环境,测试机不能联网。所以只能用scp上传nginx源码安装。期间遇到不少问题


1.下载nginx源码

$wget 'http://sysoev.ru/nginx/nginx-1.2.6.tar.gz'


2.下载lua-nginx-module源码

$git clone https://github.com/chaoslawful/lua-nginx-module.git

$tar zcvf lua-nginx-module


//上传到测试机

//$scp -p nginx-1.2.6.tar.gz port user@ip:nginx-1.2.6.tar.gz


3.编译nginx

$tar -zxvf nginx-1.2.6.tar.gz

$cd nginx-1.2.6.tar.gz

$configure --add-module=/root/lua-nginx-module


提示找不到lua库


安装lua源码。在lua.org官方主页下载源代码,一开始我直接下的最新版,最后才发现:

ngx_lua does not support Lua 5.2.Only Lua 5.1.x and LuaJIT 2.0 are supported. Seehttp://wiki.nginx.org/HttpLuaModule#Installation


后悔没先看wiki,http://wiki.nginx.org/HttpLuaModule#Installation


4.下载lua源码

$wget http://www.lua.org/ftp/lua-5.1.5.tar.gz

$tar -zxvf lua-5.1.5.tar.gz

$make linux


gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lua.o lua.c
在包含自 lua.h:16 的文件中,
                 从 lua.c:15:
luaconf.h:275:31: 错误:readline/readline.h:没有那个文件或目录
luaconf.h:276:30: 错误:readline/history.h:没有那个文件或目录


5.安装readline

$wget ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz

$tar -zxvf readline-6.2.tar.gz

$./configure

$make install


再重新编译lua, 提示-lncurses失败,也就是没有ncurses库

/usr/bin/ld: cannot find -lncurses
collect2: ld 返回 1
make[2]: *** [lua] 错误 1
make[2]: Leaving directory `/root/lua-5.1.5/src'
make[1]: *** [linux] 错误 2
make[1]: Leaving directory `/root/lua-5.1.5/src'
make: *** [linux] 错误 2


6.安装ncurses

$wget ftp://invisible-island.net/ncurses/ncurses-5.9.tar.gz

$tar -zxvf ncurses-5.9.tar.gz

$./configure

$make & make install


执行到中途,提示:

/bin/sh: -I../c++: 没有那个文件或目录
make[1]: *** [../objects/cursesf.o] 错误 127
make[1]: Leaving directory `/root/ncurses-5.9/c++'
make: *** [all] 错误 2


这个问题纠结了好长时间,在http://forums.gentoo.org/viewtopic-p-2641060.html找到相关的,但是发现是gentoo系统。不过也试了试安装g++,下载g++源码时发现完整的包有78M,就偷懒下了个gcc-g++-xxx.tar.gz。最后解压发现不完整,根本不能编译。


最后才在http://lists.gnu.org/archive/html/bug-ncurses/2007-03/msg00048.html找到答案。

If you don't have a c++ compilter, try adding --without-cxx to your
./configure line.

安装ncurse
$./configure --without-cxx

$make & make install


7.安装nginx(因为主要目的是测试lua模块,所以没安装http_rewrite模块和http_gzip模块)

$./configure --add-module=/root/lua-nginx-module --without-http_rewrite_module --without-http_gzip_module

$make install 


提示

/usr/local/lib/liblua.a(loadlib.o): In function `ll_loadfunc':
loadlib.c:(.text+0x7d4): undefined reference to `dlsym'
loadlib.c:(.text+0x7e2): undefined reference to `dlerror'
loadlib.c:(.text+0x8ad): undefined reference to `dlopen'
loadlib.c:(.text+0x8c3): undefined reference to `dlerror'
/usr/local/lib/liblua.a(loadlib.o): In function `gctm':
loadlib.c:(.text+0xdbc): undefined reference to `dlclose'
collect2: ld 返回 1
make[1]: *** [objs/nginx] 错误 1
make[1]: Leaving directory `/root/nginx-1.2.7'
make: *** [install] 错误 2


根据http://www.linuxquestions.org/questions/programming-9/linker-problems-cannot-find-dlsym-dlopen-dlerror-dlclose-720199/的提示,在obj/Makefile的对应位置(搜索llua)添加-ldl选项


终于搞定!


后记:

因为要使用set指令,无奈必须安装rewrite模块。


又需要安装 pcre, g++, gmp,mpfr,mpc ...


安装g++

http://gcc.gnu.org/ml/gcc-help/2010-09/msg00005.html


checking for x86_64-unknown-linux-gnu-gcc... /root/gcc-4.6.1/host-x86_64-unknown-linux-gnu/gcc/xgcc -B/root/gcc-4.6.1/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include   
checking for suffix of object files... configure: error: in `/root/gcc-4.6.1/x86_64-unknown-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] 错误 1
make[2]: Leaving directory `/root/gcc-4.6.1'
make[1]: *** [stage1-bubble] 错误 2
make[1]: Leaving directory `/root/gcc-4.6.1'
make: *** [all] 错误 2


http://gcc.gnu.org/wiki/FAQ#configure_suffix


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值