安装必要的编译工具:

yum groupinstall "Development Tools" "Server Platform Development"

下载openssl:

https://www.openssl.org/source/

编译安装:不安装也行,只是安装nginx需要openssl的源码。

cd /usr/local
tar zxvf openssl-1.1.1c.tar.gz
cd openssl-1.1.1c
./config --prefix=/usr/local/openssl
make && make install

升级本地版本:这个要升级一下,因为openssl命令要加载库文件,不过不影响nginx的编译。

mv /usr/bin/openssl /usr/bin/openssl.OFF
mv /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
ldconfig -v

查看版本:

openssl version -a


下载nginx依赖pcre:需要和nginx一起编译

http://www.pcre.org/

解压:解压即可,安装不是必须的,除非想升级本地版本。

cd /usr/local
tar -zxv -f pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/usr/local/pcre/
make && make install


下载依赖zlib:

http://www.zlib.net/

解压:不必安装,解压即可。

cd /usr/local
tar -zxv -f zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib/
make && make install


下载nginx:

nginx.org/en/download.html

编译安装:

./configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--modules-path=/usr/lib/nginx/modules \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-openssl=/root/openssl-1.1.1c \ # openssl的源码目录
--with-pcre=/root/pcre-8.43 \ # pcre的源码目录
--with-zlib=/root/zlib-1.2.11 \ # zlib的源码目录
--with-debug \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-cc-opt='-g -O2 -Wp,-D_FORTIFY_SOURCE=2'

用新版的openssl测试:

./openssl s_client -connect buickmallpc.chexiang.com:443 -tls1_1
./openssl s_client -connect buickmallpc.chexiang.com:443 -tls1_2
./openssl s_client -connect buickmallpc.chexiang.com:443 -tls1_3