Linux中编译、安装nginx

Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP 代理服务器。 Nginx 是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。
作为开源的服务器软件,在Linux系统中安装和其他开源软件的安装方法大同小异,无非就是编译,然后安装。下面介绍我编译安装nginx的过程:
工作机器各项参数如下:
CPU:Intel Xeon 5110
内存:DDR2 1G*4
主机型号:ProLiant DL140 G3
操作系统:Red Hat Enterprise Linux Server release 5.4 x86_64版
内核版本:2.6.18
gcc版本:4.1.2
g++版本:4.1.2

1.下载nginx源码:
截止到今天(2011年11月24日),最新的稳定版的nginx服务器版本号为1.0.10,可以从nginx的官方网站http://www.nginx.org/中下载到其源代码。
这里强烈建议下载tar.gz格式的压缩包。在Linux下,文件访问有着严格的权限限制。一个文件是否允许以二进制或者脚本的形式执行,完全取决于其是否拥有执行缺陷,这与Windows识别文件后缀名(.exe、.bat)的方式不同。zip格式的压缩包中是不保留文件的权限信息的,而tar.gz格式的压缩包是保存有文件的权限信息的。
下载nginx的tar.gz格式源码包
然后对其解压,并执行编译配置脚本:
[plain] view plaincopy
[root@lxp2 Downloads]# tar -xf nginx-1.0.10.tar.gz
[root@lxp2 Downloads]# cd nginx-1.0.10
[root@lxp2 nginx-1.0.10]# ./configure
脚本执行到最后可能会报出如下错误:
[plain] view plaincopy
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[root@lxp2 nginx-1.0.10]#
这说明系统中缺少PCRE库。该库是实现正则表达式的基础,如果缺少此库,nginx无法支持HTTP中的URL重写功能。如果你不需要此功能,可以在执行编译配置脚本时加入“--without-http_rewrite_module”。但是,这里我们需要这项功能。于是下载PCRE库。

2.下载安装PCRE库:
PCRE库是实现Perl式正则表达式的基础。如果系统中缺少此库需要编译安装。可以从著名的开源软件网站sourceforge上下载:http://sourceforge.net/projects/pcre/files/pcre/。目前最新版本是8.20。
仍然是下载后解压、配置、编译和安装:
[plain] view plaincopy
[root@lxp2 Downloads]# tar -xf pcre-8.20.tar.gz
[root@lxp2 Downloads]# cd pcre-8.20
[root@lxp2 pcre-8.20]# ./configure
[root@lxp2 pcre-8.20]# make
[root@lxp2 pcre-8.20]# sudo make install

3.编译nginx:
如果编译配置脚本正常运行,会在最后报告出nginx将要安装的位置以及其他相关信息。阅读过之后直接编译就好:
[plain] view plaincopy
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@lxp2 nginx-1.0.10]# make
然后安装:
[plain] view plaincopy
[root@lxp2 nginx-1.0.10]# sudo make install
至此nginx安装完毕。

posted @ 2013-11-26 17:17  Earic  阅读(333)  评论(0编辑  收藏  举报