免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2203 | 回复: 0
打印 上一主题 下一主题

Linux中编译、安装nginx . [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-25 14:04 |只看该作者 |倒序浏览
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源码:

最新的稳定版的nginx服务器版本号为1.0.10,可以从nginx的官方网站http://www.nginx.org/中下载到其源代码。

这里强烈建议下载tar.gz格式的压缩包。在Linux下,文件访问有着严格的权限限制。一个文件是否允许以二进制或者脚本的形式执行,完全取决于其是否拥有执行缺陷,这与Windows识别文件后缀名(.exe、.bat)的方式不同。zip格式的压缩包中是不保留文件的权限信息的,而tar.gz格式的压缩包是保存有文件的权限信息的。



然后对其解压,并执行编译配置脚本:
  1. view plaincopy to clipboardprint?
  2. 01.[root@lxp2 Downloads]# tar -xf nginx-1.0.10.tar.gz   
  3. 02.[root@lxp2 Downloads]# cd nginx-1.0.10  
  4. 03.[root@lxp2 nginx-1.0.10]# ./configure   
  5. [root@lxp2 Downloads]# tar -xf nginx-1.0.10.tar.gz
  6. [root@lxp2 Downloads]# cd nginx-1.0.10
  7. [root@lxp2 nginx-1.0.10]# ./configure  
复制代码
脚本执行到最后可能会报出如下错误:
  1. view plaincopy to clipboardprint?
  2. 01.checking for PCRE library ... not found  
  3. 02.checking for PCRE library in /usr/local/ ... not found  
  4. 03.checking for PCRE library in /usr/include/pcre/ ... not found  
  5. 04.checking for PCRE library in /usr/pkg/ ... not found  
  6. 05.checking for PCRE library in /opt/local/ ... not found  
  7. 06.  
  8. 07../configure: error: the HTTP rewrite module requires the PCRE library.  
  9. 08.You can either disable the module by using --without-http_rewrite_module  
  10. 09.option, or install the PCRE library into the system, or build the PCRE library  
  11. 10.statically from the source with nginx by using --with-pcre=<path> option.  
  12. 11.  
  13. 12.[root@lxp2 nginx-1.0.10]#   
  14. checking for PCRE library ... not found
  15. checking for PCRE library in /usr/local/ ... not found
  16. checking for PCRE library in /usr/include/pcre/ ... not found
  17. checking for PCRE library in /usr/pkg/ ... not found
  18. checking for PCRE library in /opt/local/ ... not found

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

  23. [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。

仍然是下载后解压、配置、编译和安装:
  1. view plaincopy to clipboardprint?
  2. 01.[root@lxp2 Downloads]# tar -xf pcre-8.20.tar.gz   
  3. 02.[root@lxp2 Downloads]# cd pcre-8.20  
  4. 03.[root@lxp2 pcre-8.20]# ./configure  
  5. 04.[root@lxp2 pcre-8.20]# make  
  6. 05.[root@lxp2 pcre-8.20]# sudo make install  
  7. [root@lxp2 Downloads]# tar -xf pcre-8.20.tar.gz
  8. [root@lxp2 Downloads]# cd pcre-8.20
  9. [root@lxp2 pcre-8.20]# ./configure
  10. [root@lxp2 pcre-8.20]# make
  11. [root@lxp2 pcre-8.20]# sudo make install
复制代码
3.编译nginx:

如果编译配置脚本正常运行,会在最后报告出nginx将要安装的位置以及其他相关信息。阅读过之后直接编译就好:
  1. view plaincopy to clipboardprint?
  2. 01.  nginx path prefix: "/usr/local/nginx"  
  3. 02.  nginx binary file: "/usr/local/nginx/sbin/nginx"  
  4. 03.  nginx configuration prefix: "/usr/local/nginx/conf"  
  5. 04.  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"  
  6. 05.  nginx pid file: "/usr/local/nginx/logs/nginx.pid"  
  7. 06.  nginx error log file: "/usr/local/nginx/logs/error.log"  
  8. 07.  nginx http access log file: "/usr/local/nginx/logs/access.log"  
  9. 08.  nginx http client request body temporary files: "client_body_temp"  
  10. 09.  nginx http proxy temporary files: "proxy_temp"  
  11. 10.  nginx http fastcgi temporary files: "fastcgi_temp"  
  12. 11.  nginx http uwsgi temporary files: "uwsgi_temp"  
  13. 12.  nginx http scgi temporary files: "scgi_temp"  
  14. 13.[root@lxp2 nginx-1.0.10]# make  
  15.   nginx path prefix: "/usr/local/nginx"
  16.   nginx binary file: "/usr/local/nginx/sbin/nginx"
  17.   nginx configuration prefix: "/usr/local/nginx/conf"
  18.   nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  19.   nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  20.   nginx error log file: "/usr/local/nginx/logs/error.log"
  21.   nginx http access log file: "/usr/local/nginx/logs/access.log"
  22.   nginx http client request body temporary files: "client_body_temp"
  23.   nginx http proxy temporary files: "proxy_temp"
  24.   nginx http fastcgi temporary files: "fastcgi_temp"
  25.   nginx http uwsgi temporary files: "uwsgi_temp"
  26.   nginx http scgi temporary files: "scgi_temp"
  27. [root@lxp2 nginx-1.0.10]# make
复制代码
然后安装:
  1. view plaincopy to clipboardprint?
  2. 01.[root@lxp2 nginx-1.0.10]# sudo make install  
  3. [root@lxp2 nginx-1.0.10]# sudo make install
复制代码
至此nginx安装完毕。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP