CentOS6.5安装nginx1.20
2016-08-10 18:06 猎手家园 阅读(1582) 评论(0) 编辑 收藏 举报1、下载Nginx
http://nginx.org/en/download.html
nginx-1.20.0.tar.gz (已验证到当前版本)
2、安装依赖
依赖包安装顺序依次为:openssl、zlib、pcre
注:如果没有安装c++编译环境,还得安装,通过yum install gcc-c++完成安装。
yum install gcc-c++
yum install -y gcc pcre-devel openssl openssl-devel zlib-devel
(1)openssl-fips-2.0.16.tar.gz
https://www.openssl.org/source/openssl-fips-2.0.16.tar.gz
[root@mycentos mypackages]# tar xzf openssl-fips-2.0.16.tar.gz [root@mycentos mypackages]# cd openssl-fips-2.0.16 [root@mycentos openssl-fips-2.0.16]# ./config [root@mycentos openssl-fips-2.0.16]# make [root@mycentos openssl-fips-2.0.16]# make install
(2)zlib-1.2.11.tar.gz
http://zlib.net/zlib-1.2.11.tar.gz
http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz?download
[root@mycentos mypackages]# tar xzf zlib-1.2.11.tar.gz [root@mycentos mypackages]# cd zlib-1.2.11 [root@mycentos zlib-1.2.11]# ./configure [root@mycentos zlib-1.2.11]# make [root@mycentos zlib-1.2.11]# make install
(3)pcre-8.42.tar.gz
https://sourceforge.net/projects/pcre/files/pcre/8.42/
[root@mycentos mypackages]# tar xzf pcre-8.42.tar.gz [root@mycentos mypackages]# cd pcre-8.42 [root@mycentos pcre-8.42]# ./configure [root@mycentos pcre-8.42]# make [root@mycentos pcre-8.42]# make install
3、安装nginx
[root@ mycentos mypackages]# tar -zxvf nginx-1.20.0.tar.gz [root@ mycentos mypackages]# cd nginx-1.20.0 [root@ mycentos nginx-1.18.0]# ./configure --prefix=/usr/local/nginx [root@ mycentos nginx-1.18.0]# make [root@ mycentos nginx-1.18.0]# make install
如果要启用SSL模块,那么在编译的时候增加:--with-http_ssl_module 参数。
安装状态监控模块,增加参数:--with-http_stub_status_module
[root@mycentos nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module [root@mycentos nginx-1.18.0]# make #注意:切记不要进行 make install,否则就会覆盖安装!!!
注意:正常安装nginx和SSL模块安装要分开安装,合在一起安装会报错,找了好久没找到原因!
执行完做命令后,我们可以查看到在nginx解压目录下,objs文件夹中多了一个nginx的文件,这个就是新版本的程序了,然后把新的程序复制过去覆盖之前的即可(不放心你可以先备份旧的nginx)。
覆盖以后到Nginx安装目录下,查看SSL是否安装成功,执行:./sbin/nginx -V
[root@mycentos nginx]# ./sbin/nginx -V
如果有:--with-http_ssl_module,说明安装成功!
4、启动nginx
[root@ mycentos ~]# /usr/local/nginx/sbin/nginx #重启或关闭进程: [root@ mycentos ~]# /usr/local/nginx/sbin/nginx -s reload [root@ mycentos ~]# /usr/local/nginx/sbin/nginx -s stop
如果nginx启动报错:error while loading shared libraries: libpcre.so.1(低版本会报错)
我们执行一下ldd命令,会发现:libpcre.so.1 => not fund
[root@ mycentos nginx]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-vdso.so.1 => (0x00007ffd6bbe3000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fef35b10000) librt.so.1 => /lib64/librt.so.1 (0x00007fef35908000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fef356ea000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fef354b3000) libpcre.so.1 => not found libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fef35246000) libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fef34e61000) libz.so.1 => /lib64/libz.so.1 (0x0000003036e00000) libc.so.6 => /lib64/libc.so.6 (0x00007fef34acc000) /lib64/ld-linux-x86-64.so.2 (0x00007fef35d1b000) libfreebl3.so => /lib64/libfreebl3.so (0x000000303ba00000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003040600000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003040200000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fef348c7000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x000000303fe00000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x000000303f600000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003040a00000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fef346ac000) libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003036600000)
所以我们需要建立一下软连接:在 /usr/local/lib/ 和 /lib/ 和 /lib64/ 三个目录下建立软连接:
注意:我的libpcre.so.1在lib64目录下,所以只需要建立这一个软连接即可。
[root@ mycentos nginx]# ln -s /usr/local/lib/libpcre.so.0.0.1 /usr/local/lib/libpcre.so.1 [root@ mycentos nginx]# ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1
再次启动nginx,启动成功!
5、检查nginx是否启动成功
[root@mycentos ~]# cd /usr/local/nginx/sbin/ [root@mycentos sbin]# ./nginx -t
# 查看进程列表 [root@mycentos ~]# ps -ef | grep nginx # 查看进程ID [root@mycentos ~]# ps -C nginx -o pid # 查看nginx运行的80端口 [root@mycentos ~]# netstat -anp | grep :80
6、配置防火墙
[root@mycentos ~]# vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
7、浏览器访问http://127.0.0.1/