linux nginx的编译

来源:互联网 发布:剑网三明教捏脸数据 编辑:程序博客网 时间:2024/05/17 08:59

bzip2 -d pcre-7.8.tar.bz2
tar -vxf pcre-7.8.tar
 cd pcre-7.8
 ./configure
make
 make install


 nginx install
 cd /usr/local/src
 tar -zxvf nginx-0.7.43.tar.gz
 cd /usr/local/src/nginx-0.7.43
  ./configure --prefix=/usr/local/server/nginx     --with-cc-opt="-I /usr/include/pcre -I /usr/include/openssl" --with-debug    --with-http_stub_status_module       --with-http_ssl_module --with-http_realip_module --with-http_ssl_module --with-http_perl_module --with-http_stub_status_module

 

出现
nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
从错误看出是缺少lib文件导致,进一步查看下


[root@localhost conf]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-gate.so.1 =>  (0x0071b000)
libpthread.so.0 => /lib/libpthread.so.0 (0×00498000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0×00986000)
libpcre.so.1 => not found
libcrypto.so.6 => /lib/libcrypto.so.6 (0×00196000)
libz.so.1 => /lib/libz.so.1 (0×00610000)
libc.so.6 => /lib/libc.so.6 (0x002d7000)
/lib/ld-linux.so.2 (0x006a8000)
libdl.so.2 => /lib/libdl.so.2 (0x008c3000)
可以看出 libpcre.so.1 => not found 并没有找到,
因为pcre把库安装在/usr/local/lib目录下,也可以把/usr/local/lib添加在/etc/ld.so.conf文件中,然后运行ldconfig更新一下.
 
LD_LIBRARY_PATH=/usr/local/lib,
然后在启动nginx  ok 了

或者--with-pcre 指定pcre的源码路径,可以将pcre静态链入nginx.
或者编译的时候 --with-ld-opt='-L/usr/local/lib'
 
也可以编译pcre的时候./configure --prefix=/usr
 

 最简单ln -s -b  /usr/local/lib/libpcre.so.1  /usr/lib/libpcre.so.1

如果调试

 

自己添加的nginx模块难免会出现错误,所以调试就势在必行。

 
直接运行gdb nginx 会出现 No symbol table info available。

 
编译的时候 加入CFLAGS="-g -O0"  ./configure --prefix=/usr/local/server/nginx     --with-cc-opt="-I /usr/include/pcre -I /usr/include/openssl" --with-debug    --with-http_stub_status_module       --with-http_ssl_module --with-http_realip_module --with-http_ssl_module --with-http_perl_module --with-http_stub_status_module  --add-module=src/ext/helloworld

 
然后 make

 
make install
 

 

出处:http://blog.chinaunix.net/uid-192452-id-3483710.html