服务器当中nginx配置支持TLS v1.2协议的问题解决记录

本记录只是作为自己的一个心得体会,因为真的花了蛮长时间,可能并不具备通用性,所以该文档仅作参考。
前言:
安装nginx的教程,请查看我的nginx安装教程https://blog.csdn.net/u012225679/article/details/81876782(此文转载),这里不做叙述。
注意请安装支持TLS V1.2协议的openssl版本模块。

本人在项目当中要使用到微信小程序调用接口,故根据微信小程序说明文档说明,服务器应当支持https访问,并且协议要采用的TLS v1.2。我的nginx服务为淘宝服务器tengine2.10.0(nginx 1.6.2)版本。当前版本支持TLSV1.2协议。

正文:
由于当前的协议支持是在原有系统的情况进行支持TLS V1.2协议,所以原有系统是不支持该协议的。如下是通过火狐浏览器查看网站支持的协议,同样版本的nginx服务器,jdk下进行的对比:
这里写图片描述
请查看下面的TLS V1.0
下面是我自己的服务器所搭建的网站支持协议情况:
这里写图片描述
所以这两个nginx服务器一致的情况下,配置相同的情况下,非本人的网站并不支持TLS v1.2协议。
我在查看服务器的openssl的版本的时候,这两个服务器的openssl的版本都是如下:
这里写图片描述
请注意:该版本的openssl如果是使用 openssl version这个命令的话,该模块并不一定是你nginx编译安装的openssl版本模块。(因为死在这里了,所以影响深刻)。
然后进入nginx的安装目录的sbin目录下,通过执行查看nginx的安装模块:

./nginx -V
configure arguments: --prefix=/home/xx/openresty/nginx --with-cc-opt='-I/home/xx/nginx/ngx_openresty/ngx_openresty/build/luajit-root/home/xx/openresty/luajit/include/luajit-2.1 -O2' --add-module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.57 --add-module=../xss-nginx-module-0.04 --add-module=../ngx_coolkit-0.2rc2 --add-module=../set-misc-nginx-module-0.28 --add-module=../form-input-nginx-module-0.10 --add-module=../encrypted-session-nginx-module-0.03 --add-module=../srcache-nginx-module-0.29 --add-module=../ngx_lua-0.9.15 --add-module=../ngx_lua_upstream-0.02 --add-module=../headers-more-nginx-module-0.25 --add-module=../array-var-nginx-module-0.03 --add-module=../memc-nginx-module-0.15 --add-module=../redis2-nginx-module-0.11 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.13 --add-module=../rds-csv-nginx-module-0.05 --with-ld-opt='-Wl,-rpath,/home/xx/openresty/luajit/lib -L/home/xx/nginx/ngx_openresty/ngx_openresty/build/luajit-root/home/xx/openresty/luajit/lib' --with-pcre=/home/xx/nginx/ngx_openresty/ngx_openresty/../pcre-7.8 --with-zlib=/home/xx/nginx/ngx_openresty/ngx_openresty/../zlib-1.2.8 --with-openssl=/home/xx/nginx/ngx_openresty/ngx_openresty/../openssl-0.9.8zf --with-http_ssl_module
loaded modules:
    ngx_core_module (static)
    ngx_errlog_module (static)
    ngx_conf_module (static)
    ngx_dso_module (static)
    ngx_syslog_module (static)
    ngx_events_module (static)
    ngx_event_core_module (static)
    ngx_epoll_module (static)
    ngx_procs_module (static)
    ngx_proc_core_module (static)
    ngx_openssl_module (static)
    ngx_regex_module (static)
    ngx_http_module (static)
    ngx_http_core_module (static)
    ngx_http_log_module (static)
    ngx_http_upstream_module (static)
    ngx_http_static_module (static)
    ngx_http_autoindex_module (static)
    ngx_http_index_module (static)
    ngx_http_auth_basic_module (static)
    ngx_http_access_module (static)
    ngx_http_limit_conn_module (static)
    ngx_http_limit_req_module (static)
    ngx_http_geo_module (static)
    ngx_http_map_module (static)
    ngx_http_split_clients_module (static)
    ngx_http_referer_module (static)
    ngx_http_rewrite_module (static)
    ngx_http_ssl_module (static)
    ngx_http_proxy_module (static)
    ngx_http_fastcgi_module (static)
    ngx_http_uwsgi_module (static)
    ngx_http_scgi_module (static)
    ngx_http_memcached_module (static)
    ngx_http_empty_gif_module (static)
    ngx_http_browser_module (static)
    ngx_http_user_agent_module (static)
    ngx_http_upstream_ip_hash_module (static)
    ngx_http_upstream_consistent_hash_module (static)
    ngx_http_upstream_check_module (static)
    ngx_http_upstream_least_conn_module (static)
    ngx_http_reqstat_module (static)
    ngx_http_upstream_keepalive_module (static)
    ngx_http_upstream_dynamic_module (static)
    ngx_http_stub_status_module (static)
    ndk_http_module (static)
    ngx_coolkit_module (static)
    ngx_http_lua_upstream_module (static)
    ngx_http_memc_module (static)
    ngx_http_redis2_module (static)
    ngx_http_redis_module (static)
    ngx_http_write_filter_module (static)
    ngx_http_header_filter_module (static)
    ngx_http_chunked_filter_module (static)
    ngx_http_range_header_filter_module (static)
    ngx_http_gzip_filter_module (static)
    ngx_http_postpone_filter_module (static)
    ngx_http_ssi_filter_module (static)
    ngx_http_charset_filter_module (static)
    ngx_http_userid_filter_module (static)
    ngx_http_footer_filter_module (static)
    ngx_http_trim_filter_module (static)
    ngx_http_headers_filter_module (static)
    ngx_http_upstream_session_sticky_module (static)
    ngx_http_echo_module (static)
    ngx_http_xss_filter_module (static)
    ngx_http_set_misc_module (static)
    ngx_http_form_input_module (static)
    ngx_http_encrypted_session_module (static)
    ngx_http_srcache_filter_module (static)
    ngx_http_lua_module (static)
    ngx_http_headers_more_filter_module (static)
    ngx_http_array_var_module (static)
    ngx_http_rds_json_filter_module (static)
    ngx_http_rds_csv_filter_module (static)
    ngx_http_copy_filter_module (static)
    ngx_http_range_body_filter_module (static)
    ngx_http_not_modified_filter_module (static)

发现loaded module上面的一行的后面,发现了openssl-0.9.8zf,这个版本的openssl并不支持TLSv1.2的协议(先让我默哀一分钟)。

所以最后只能采用升级openssl了。
升级的步骤也比较简单,下载好openssl的模块之后,这里采用的openssl-1.0.1e,解压缩到某个目录下。

[root@VM_0_2_centos software]# ll
total 152892
drwxr-xr-x  9 root  root       4096 Aug 22 12:41 apache-tomcat-8.0.53
-rw-r--r--  1 root  root    9455895 Jun 30 00:39 apache-tomcat-8.0.53.tar.gz
drwxr-xr-x  8 uucp    143      4096 Oct  8  2013 jdk1.7.0_45
-rw-r--r--  1 root  root  138094686 Aug 21 19:44 jdk-7u45-linux-x64.tar.gz
*drwxr-xr-x 23 root  root       4096 Aug 22 13:43 openssl-1.0.1e
-rw-r--r--  1 root  root    4459777 Aug 22 10:57 openssl-1.0.1e.tar.gz*
drwxr-xr-x  9  1169  1169     12288 Aug 22 13:43 pcre-8.40
-rw-r--r--  1 root  root    2065161 Aug 22 11:19 pcre-8.40.tar.gz
drwxr-xr-x 12 50469 users      4096 Aug 22 13:41 tengine-2.1.0
-rw-r--r--  1 root  root    1653240 Aug 21 16:10 tengine-2.1.0.tar.gz
drwxr-xr-x 14   501 games      4096 Aug 22 13:44 zlib-1.2.11
-rw-r--r--  1 root  root     607698 Jan 16  2017 zlib-1.2.11.tar.gz
[root@VM_0_2_centos software]#

我这里是放在了/opt/software/目录下:
其实不需要重新编译或者安装,至少基于我这台服务器的安装环境不需要,也就是说下载下来的源码,解压缩就可以了。

然后进入到nginx的源码安装目录,由于我这边两个文件在同一个目录下,所以直接进入:

[root@VM_0_2_centos software]# ll
total 152892
drwxr-xr-x  9 root  root       4096 Aug 22 12:41 apache-tomcat-8.0.53
-rw-r--r--  1 root  root    9455895 Jun 30 00:39 apache-tomcat-8.0.53.tar.gz
drwxr-xr-x  8 uucp    143      4096 Oct  8  2013 jdk1.7.0_45
-rw-r--r--  1 root  root  138094686 Aug 21 19:44 jdk-7u45-linux-x64.tar.gz
drwxr-xr-x 23 root  root       4096 Aug 22 13:43 openssl-1.0.1e
-rw-r--r--  1 root  root    4459777 Aug 22 10:57 openssl-1.0.1e.tar.gz
drwxr-xr-x  9  1169  1169     12288 Aug 22 13:43 pcre-8.40
-rw-r--r--  1 root  root    2065161 Aug 22 11:19 pcre-8.40.tar.gz
drwxr-xr-x 12 50469 users      4096 Aug 22 13:41 tengine-2.1.0
-rw-r--r--  1 root  root    1653240 Aug 21 16:10 tengine-2.1.0.tar.gz
drwxr-xr-x 14   501 games      4096 Aug 22 13:44 zlib-1.2.11
-rw-r--r--  1 root  root     607698 Jan 16  2017 zlib-1.2.11.tar.gz
[root@VM_0_2_centos software]# cd tengine-2.1.0
[root@VM_0_2_centos tengine-2.1.0]# ./configure --prefix=/usr/local/tools/nginx2 --with-pcre=/opt/software/pcre-8.40 --with-zlib=/opt/software/zlib-1.2.11 --with-openssl=/opt/software/openssl-1.0.1e --with-http_ssl_module

上面的./configure 命令请注意修改 –with-openssl的参数值,改成openssl-1.0.1e的源码解压缩目录即可。
完成之后然后,直接make && make install 。

[root@VM_0_2_centos tengine-2.1.0]# make && make install

安装完成之后,就可以在/usr/local/tools/当中有nginx2的目录和内容了。可以不创建nginx2目录,会自动创建:

[root@VM_0_2_centos sbin]# cd /usr/local/tools/
[root@VM_0_2_centos tools]# ll
total 28
drwxr-xr-x 13 root root 4096 Aug 22 12:38 nginx
drwxr-xr-x 13 root root 4096 Aug 22 13:39 nginx1
drwxr-xr-x 13 root root 4096 Aug 22 13:45 nginx2
drwxr-xr-x  6 root root 4096 Aug 22 12:22 openssl
drwxr-xr-x  6 root root 4096 Aug 22 12:23 pcre
-rw-r--r--  1 root root  634 Aug 22 12:33 server.txt
drwxr-xr-x  5 root root 4096 Aug 22 12:24 zlib

最后,修改nginx的配置文件以支持https的协议,请参考我的https协议配置文档https://blog.csdn.net/u012225679/article/details/81872876,当然,ssl证书是必不可少的。可以网上搜索一下,或者后期我会再更新一个申请ssl证书的文档。
最后,访问网站,查看协议,如下图所示:
这里写图片描述
如下便是安装完成了。

学习、成长
原文地址:https://www.cnblogs.com/yarcl/p/11046762.html