操作系统环境版本redhat-release 7.2
编译环境准备:
安装make
#yum -y install gcc automake autoconf libtool make
安装g++
#yum install gcc gcc-c++ -y
需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩
相关版本使用如下:
pcre-8.43.tar.gz
zlib-1.2.11.tar.gz
openssl-1.0.2t.tar.gz
nginx-1.16.1.tar.gz
将文件上传到路径/usr/local/src
cd /usr/local/src
tar -zxvf pcre-8.43.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf openssl-1.0.2t.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
源码安装pcre
cd /usr/local/src/pcre-8.43
./configure --prefix=/usr/local/pcre
make && make install
源码安装zlib
cd /usr/local/src/zlib-1.2.11
./configure --prefix=/usr/local/zlib
make && make install
部分操作系统已经安装openssl,可用openssl version -a命令检查已安装的openssl的信息
系统已经安装了openssl,我们可以先安装新的版本,然后将环境配置成最新的版本
[root@hostname /]# openssl version -a
OpenSSL 1.0.1e-fips 11 Feb 2013
built on: Wed Oct 15 10:59:09 UTC 2014
platform: linux-x86_64
options: bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wa,–noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: “/etc/pki/tls”
engines: dynamic
[root@hostname /]#
源码安装新版本openssl
cd /usr/local/src/openssl-1.0.2t
./config shared zlib --prefix=/usr/local/openssl
make && make install
更新版本相关配置
mv -f /usr/bin/openssl /usr/bin/openssl.OFF
mv -f /usr/include/openssl /usr/include/openssl.OFF
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
/sbin/ldconfig -v
/sbin/ldconfig
检查更新
[root@hostname /]# openssl version -a
OpenSSL 1.0.2t 10 Sep 2019
built on: reproducible build, date unspecified
platform: linux-x86_64
options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -I. -I… -I…/include -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,–noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: “/usr/local/openssl/ssl”
[root@hostname /]#
安装nginx(--with-pcre=DIR 是设置源码目录,而不是编译安装后的目录)
cd /usr/local/src/nginx-1.16.1
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.2t
make && make install
第二种安装方式
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* pcre-devel -y
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.43
--with-http_dav_module #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认关闭,需要编译开启
--with-http_stub_status_module #启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)
--with-pcre=/usr/local/src/pcre-8.37 #需要注意,这里指的是源码,
#用#./configure --help |grep pcre查看帮助
检查配置文件、启停方式
[root@XueGod63 ~]# /usr/local/nginx/sbin/nginx -t #检查配置文件语法是否有错误
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@XueGod63 ~]# /usr/local/nginx/sbin/nginx -s reload #重新加载配置文而建(平滑重启)
[root@XueGod63 ~]# /usr/local/nginx/sbin/nginx -s stop #停止Nginx,注意:启动没有任何参数
[root@XueGod63 ~]# echo "/usr/local/nginx/sbin/nginx &" >> /etc/rc.local #开机启动
#平滑重启(保持了C-S链接,不断开,服务器只是重新加载了配置文件,没有开启和关闭的服务器的一个动作)
参考链接:http://www.nginx.cn/install
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)