系统:Centos 6.0
一、安装之前首先确认系统中是否已安装gcc、openssl-devel、pcre-devel、zlib-devel
序列号 | CPU | RAM | HDD | 带宽 | 售价(美元) | 免费试用 |
---|---|---|---|---|---|---|
香港服务器1 | E5-2620 | 32G | 1T HDD | 50M/无限流量 | $196.00 | 立即申请 |
香港服务器2 | E5-2650 | 32G | 1T HDD | 50M/无限流量 | $256.00 | 立即申请 |
香港服务器3 | E5-2680 | 32G | 1T HDD | 50M/无限流量 | $316.00 | 立即申请 |
香港服务器4 | E5-2690 | 32G | 1T HDD | 50M/无限流量 | $336.00 | 立即申请 |
香港服务器5 | E5-2697 | 32G | 1T HDD | 50M/无限流量 | $376.00 | 立即申请 |
香港服务器6 | E5-2620*2 | 32G | 1T HDD | 50M/无限流量 | $376.00 | 立即申请 |
香港服务器7 | E5-2650*2 | 32G | 1T HDD | 50M/无限流量 | $436.00 | 立即申请 |
香港服务器8 | E5-2680*2 | 32G | 1T HDD | 50M/无限流量 | $476.00 | 立即申请 |
香港服务器9 | E5-2690*2 | 32G | 1T HDD | 50M/无限流量 | $556.00 | 立即申请 |
香港服务器10 | E5-2697*2 | 32G | 1T HDD | 50M/无限流量 | $596.00 | 立即申请 |
香港服务器11 | E5-2680v4*2 | 32G | 1T HDD | 50M/无限流量 | $696.00 | 立即申请 |
香港服务器12 | E5-2698v4*2 | 32G | 1T HDD | 50M/无限流量 | $796.00 | 立即申请 |
#yum -y install gccopenssl-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
问题: libtool: compile: unrecognized option`-DHAVE_CONFIG_H' libtool: compile: Try `libtool --help' for moreinformation. 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++
三、安装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支持在线实时压缩输出数据流。
问题:
1、若在./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解压缩包的路径
2、若在“./configure”后方加入了“--with-http_gzip_static_module”(添加gzip压缩模块)提示以下错误:./configure: error: the HTTP gzip module requires the zliblibrary.You can either disable the module by using--without-http_gzip_moduleoption, or install the zlib library into the system, or build thezlib librarystatically from the source with nginx by using--with-zlib=
解决办法:安装zlib-devel包
#yum -y install zlib-devel
启动Nginx出现的问题:# /usr/local/nginx/sbin/nginx
1、/usr/local/nginx/sbin/nginx: error while loading sharedlibraries: libpcre.so.1: cannot open shared object file: No suchfile or directory
从错误看出是缺少lib文件导致,进一步查看下
# 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 foundlibcrypto.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 并没有找到,进入/lib目录中手动链接下# ln -s libpcre.so.0.0.1 libpcre.so.1
然后在启动nginx ok 了# /usr/local/nginx/sbin/nginx# ps -aux|grep nginxWarning: bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.7/FAQroot 28254 0.0 0.0 2688 460 ? Ss 17:16 0:00 nginx: master process/usr/local/nginx/sbin/nginxnobody 28255 0.0 0.0 2860 816 ? S 17:16 0:00 nginx: workerprocessroot 28265 0.0 0.0 4160 688 pts/1 R+ 17:16 0:00 grep nginx
2、Nginx启动失败,提示端口已被占用提示:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alreadyin use)nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already inuse)nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already inuse)nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already inuse)
解决如下图所示:
先用#netstat -ntlp 查看端口被哪个服务给占用
其次用#kill -9 PID 杀掉进程号 (进程号杀不死用 killall -9)
在启用nginx
打开浏览器:http://localhost 显示Welcome to Nginx至此Nginx安装完毕。