在我们的web项目部署中常常会遇到一台机器部署个项目,或者一个项目多台机器部署做负载,这个时候我们就会发现我们的80端口不够用,或者说我们的项目路径很难处理,这个时候我们经常会用到反向代理工具,我接触到比较多的是Nginx! (一)Nginx的安装 相关软件下载地址: nginx(nginx-1.2.4.tar.g) http://nginx.org/ pcre(pcre-8.31.tar.gz) http://pcre.org/ ① 安装之前首先确认系统中是否已安装gcc、openssl-devel、pcre-devel、zlib-devel #yum -y install gcc openssl-devel pcre-devel zlib-devel ② 安装pcre-devel库(使Nginx支持http rewrite的模块) #tar zxvf pcre-8.31.tar.gz (解压) #cd pcre-8.31 #./congigure #make #make install ③安装Nginx #tar zxvf nginx-1.2.4.tar.gz #cd nginx-1.2.4 #./configure --with-http_stub_status_module --with-http_gzip_static_module-- prefix=/usr/local/nginx #make #makeinstall 注:--with-http_stub_status_module 可以用来启用Nginx的NginxStatus功能,以监控Nginx的当前状态。 --with-http_gzip_static_module 支持在线实时压缩输出数据流 ④ 启用nginx # /usr/local/nginx/sbin/nginx 打开浏览器: http://localhost 显示Welcome to Nginx,至此Nginx安装完毕! 通过上面是三步基本上是已经将Nginx安装成功的,但是我们经常会在安装过程中遇到各种各样的问题,我将我遇到的一些问题做了一个checklist,方便有需要的查阅: 问题一: libtool: compile: unrecognized option `-DHAVE_CONFIG_H' libtool: compile: Try `libtool --help' for more information. make[1]: *** [pcrecpp.lo] Error 1 make[1]: Leaving directory `/home/guangbo/work/pcre-8.12' make: *** [all] Error 2 缺少gcc-c++和libtool,也就是c++编译包 解决方法:需要先安装libtool和gcc-c++ #yum -y install libtool #yum -y install gcc-c++ 问题二:若在./configure后配置刚才的参数,提示一下的错误: objs/src/http/modules/ngx_http_browser_module.o \ objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \objs/src/http/modules/ngx_http_upstream_least_conn_module.o \objs/src/http/modules/ngx_http_upstream_keepalive_module.o \objs/ngx_modules.o \-lpthread -lcrypt -lpcre -lcrypto -lcrypto -lzobjs/src/core/ngx_regex.o: In function `ngx_pcre_free_studies':/share/nginx-1.2.4/src/core/ngx_regex.c:307: undefined reference to `pcre_free_study'collect2: ld returned 1 exit statusmake[1]: *** [objs/nginx] Error 1make[1]: Leaving directory `/share/nginx-1.2.4'make: *** [build] Error 2 解决方法: ./configure --prefix=/usr/local/nginx --without-http_autoindex_module --without-http_geo_module --without-http_map_module --without-http_browser_module --with-http_stub_status_module --with-http_realip_module --with-pcre=../pcre-8.31 PS: ./configure --prefix=/usr/localnx --without-http_autoindex_module --without-http_geo_module --with-pcre=../pcre-8.31 注意:把--with-pcre=../pcre-8.31换成你的pcre解压缩包的路径 问题三:若在“./configure”后方加入了“--with-http_gzip_static_module”(添加gzip压缩模块)提 示以下错误: ./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option. 解决办法:安装zlib-devel包 #yum -y install zlib-devel 问题四:Nginx启动失败,提示端口已被占用提示: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 解决如下图所示:
先用#netstat -ntlp 查看端口被哪个服务给占用, 其次用#kill -9 PID 杀掉进程号 (进程号杀不死用 killall -9)再 启用nginx! 通过以上步骤以及问题解决方案,解决在Centos上安装Nginx基本上是没有任何问题,如有问题可以留言讨论,感谢翻阅! (责任编辑:最模板) |