linux nginx的编译

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 1. 下载nginx1.22.0源码包 2. 解压源码包:tar -zxvf nginx-1.22.0.tar.gz 3. 安装依赖库:yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 4. 进入nginx源码目录:cd nginx-1.22.0 5. 配置编译选项:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module 6. 编译安装:make && make install 7. 启动nginx:/usr/local/nginx/sbin/nginx 8. 验证nginx是否启动成功:访问http://localhost,如果出现“Welcome to nginx!”则表示安装成功。 ### 回答2: 安装编译前的准备 在开始安装编译Linux Nginx之前,您需要在服务器上安装一些准备工作。下面是一些必要的准备工作。 1. 确保服务器上已经安装了GCC(GNU Compiler Collection)。 2. 确保服务器上已经安装了Make工具。 3. 在安装Linux Nginx之前,必须安装PCRE(Perl Compatible Regular Expressions)和zlib库。这些库用于提供正则表达式的支持和压缩算法。 4. 确保已经安装了OpenSSL(Secure Sockets Layer)库。这些库用于提供安全的HTTP传输协议。 步骤1:下载Linux Nginx 首先,您需要下载Linux Nginx。请选择可靠的站点或官方网站以确保文件是安全的。 此外,您也可以使用wget命令从服务器上下载Linux Nginx。例如: $ wget http://nginx.org/download/nginx-1.22.0.tar.gz 步骤2:解压缩Linux Nginx 下载完成后,您需要使用以下命令来将Linux Nginx解压缩。 $ tar -zxvf nginx-1.22.0.tar.gz 步骤3:编译并安装 在解压缩完成后,您需要切换到存储目录并开始编译安装。 $ cd nginx-1.22.0 $ ./configure --with-http_ssl_module $ make $ make install 请注意,上面的编译选项“--with-http_ssl_module”用于启用SSL模块。 步骤4:运行Linux Nginx编译安装完成后,您需要启动Linux Nginx。使用以下命令来启动。 $ nginx 此外,您还可以使用以下一些操作来控制Linux Nginx的行为。 $ nginx -s stop // 停止Nginx。 $ nginx -s quit // 优雅地停止Nginx。 $ nginx -s reload // 重新加载配置文件。 总结 编译安装Linux Nginx的过程相对简单,但需要一些准备工作和基本的Linux知识。在安装之前,请确保具备所需的先决条件,并根据需要进行设置和配置。使用上述步骤,您可以轻松编译和安装Linux Nginx,并使用其提供的高性能的HTTP和Web服务器功能。 ### 回答3: linux系统是一种基于UNIX操作系统的自由软件和开源软件,被广泛应用于各种领域。NGINX是一种高性能、高可靠性的Web服务器和反向代理服务器,被广泛应用于负载均衡、缓存、HTTP代理等方面。本文将详细介绍在linux系统下编译安装NGINX1.22.0的步骤及注意事项。 一、环境准备 首先需要确保linux系统中已经安装了必要的依赖库,例如gcc、pcre、openssl、zlib等。可以通过以下命令进行检查和安装: ``` $ sudo apt-get update $ sudo apt-get install gcc $ sudo apt-get install libpcre3 libpcre3-dev $ sudo apt-get install openssl libssl-dev $ sudo apt-get install zlib1g-dev ``` 二、下载NGINX源码 在编译安装NGINX之前,需要先从官方网站(https://nginx.org/en/download.html)下载最新版的源码包。下载完成后,将源码包解压到指定目录中,例如: ``` $ tar -zxvf nginx-1.22.0.tar.gz $ cd nginx-1.22.0 ``` 三、配置编译参数 在编译安装NGINX之前,需要为NGINX配置编译参数,例如安装目录、模块、日志等。可以通过以下命令进行配置: ``` $ sudo ./configure \ --prefix=/usr/share/nginx \ --sbin-path=/usr/sbin/nginx \ --modules-path=/usr/lib/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-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-compat \ --with-pcre \ --with-pcre-jit \ --with-openssl \ --with-zlib ``` 其中常用的参数解释如下: prefix:指定安装的目录; sbin-path:指定NGINX的可执行文件路径; modules-path:指定NGINX模块的安装路径; conf-path:指定NGINX的配置文件路径; error-log-path:指定NGINX的错误日志路径; http-log-path:指定NGINX的访问日志路径; pid-path:指定NGINX的进程ID文件路径; user/group:指定运行NGINX的用户和组; with-xxx:指定要编译的模块; with-compat:是为了保持NGINX现有配置和第三方模块的兼容性。 四、编译安装 在完成了配置编译参数后,可以通过以下命令进行编译和安装: ``` $ sudo make $ sudo make install ``` 如果编译和安装过程没有出现错误提示,则说明NGINX已经成功安装到了指定目录中。 五、启动NGINX 完成了NGINX编译安装后,需要通过以下命令启动NGINX: ``` $ sudo /usr/sbin/nginx ``` 如果没有出现错误提示,则说明NGINX已经启动成功。可以通过访问http://localhost:80测试NGINX是否能正常响应。 六、总结 在linux系统下编译安装NGINX1.22.0并不困难,需要先准备好必要的依赖库,下载源码并配置编译参数,最后进行编译和安装。同时,可以根据自己的需要进行相应的参数配置,例如安装目录、模块等。在NGINX启动后,可以通过http://localhost:80进行访问,测试是否能正常响应。使用NGINX可以大大提高Web服务器的性能和可靠性,对于高并发和大流量的场景更是有很好的应用效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值