Nginx/Haproxy实现OpenSSL升级方案+证书安全检测步骤(ssl证书nginx配置)

网友投稿 462 2022-10-08


Nginx/Haproxy实现OpenSSL升级方案+证书安全检测步骤(ssl证书nginx配置)

防伪码:生当作人杰,死亦为鬼雄。

一、Haproxy篇:

1、centos6.5系统[root@yangwen ~]# cat /etc/redhat-release CentOS release 6.5 (Final)[root@yangwen ~]# uname -r2.6.32-431.el6.x86_642、下载并编译安装openssl[root@yangwen ~]# wget ~]# tar zxf openssl-1.1.1.tar.gz [root@yangwen ~]# cd openssl-1.1.1[root@yangwen openssl-1.1.1]# ./config --prefix=/usr/local/[root@yangwen openssl-1.1.1]# make && make install[root@yangwen openssl-1.1.1]# echo /usr/local/openssl/lib >>/etc/ld.so.conf[root@yangwen ~]# ln -sf /usr/local/lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1[root@yangwen ~]# ln -sf /usr/local/lib64/libssl.so.1.1 /lib64/libssl.so.1.1[root@yangwen ~]# openssl versionOpenSSL 1.1.1  11 Sep 2018下载haprox并编译安装(支持openssl,可以去此网站下载~]# cat /etc/redhat-release CentOS release 6.5 (Final)[root@yangwen ~]# uname -r2.6.32-431.el6.x86_642、编译安装nginx且支持openssl

脚本如下:

#!/bin/bash wget -P /usr/local/src  http://nginx.org/download/nginx-1.15.6.tar.gz wget -P /usr/local/src  https://openssl.org/source/openssl-1.1.1.tar.gz yum -y install epel-release yum -y install patch gcc gcc-c++  readline-devel zlib-devel libffi-devel \  openssl openssl-devel make autoconf automake libtool bison libxml2 \  libxml2-devel libxslt-devel libyaml-devel  python  python-docutils \  cmake imake expat-devel libaio libaio-devel bzr ncurses-devel wget \  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel  \  pcre-devel curl-devel libmcrypt libmcrypt-devel id nginx &> /dev/null if [ $? -ne 0 ];then   groupadd -r nginx   useradd -g nginx -r nginx fi cd /usr/local/src tar -xvf openssl-1.1.1.tar.gz tar -xvf nginx-1.15.6.tar.gz cd /usr/local/src/nginx-1.15.6 ./configure --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-threads \ --with-stream \ --with-openssl=/usr/local/src/openssl-1.1.1 \ --with-stream_ssl_module \ --with-http_slice_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-http_v2_module \ --with-ipv6  mkdir -pv /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp} make && make install

[root@yangwen ~]# /usr/sbin/nginx [root@yangwen ~]# ps -ef | grep nginxroot      15935      1  0 20:38 ?        00:00:00 nginx: master process /usr/sbin/nginxnginx     15936  15935  0 20:38 ?        00:00:00 nginx: worker processroot      15939   2510  0 20:38 pts/1    00:00:00 grep nginx[root@yangwen ~]# netstat -anpt | grep nginxtcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      15935/nginx         [root@yangwen ~]# curl -I 127.0.0.1HTTP/1.1 200 OKServer: nginx/1.11.7Date: Tue, 20 Nov 2018 12:38:58 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Tue, 20 Nov 2018 12:38:07 GMTConnection: keep-aliveETag: "5bf4002f-264"Accept-Ranges: bytes

[root@yangwen ~]# nginx -Vnginx version: nginx/1.11.7built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) built with OpenSSL 1.1.0e  16 Feb 2017TLS SNI support enabledconfigure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log ----pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock ------------user=nginx --group=nginx --with---with---with---with---with---with---with---with---with---with---with---with---with---with-threads --with-stream --with-openssl=/usr/local/src/openssl-1.1.0e --with-stream_ssl_module --with---with-mail --with-mail_ssl_module --with-file-aio --with---with-ipv6

3、升级openssl[root@yangwen ~]# wget ~]# tar zxf openssl-1.1.1.tar.gz [root@yangwen ~]# cd openssl-1.1.1[root@yangwen openssl-1.1.1]# mkdir -p /usr/local/ssl[root@yangwen openssl-1.1.1]# ./config   --openssldir=/usr/local/ssl[root@yangwen openssl-1.1.1]# make -j$(nproc) && make -j$(nproc) install

[root@yangwen openssl-1.1.1]# ln -sf /usr/local/lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1.1[root@yangwen openssl-1.1.1]# ln -sf /usr/local/lib64/libssl.so.1.1 /lib64/libssl.so.1.1[root@yangwen openssl-1.1.1]# openssl versionOpenSSL 1.1.1  11 Sep 20184、重新编译安装nginx注意次参数的路径:--with-openssl=/usr/local/src/openssl-1.1.1[root@yangwen ~]# /usr/sbin/nginx[root@yangwen ~]# ps -ef | grep nginxroot      37756      1  0 20:57 ?        00:00:00 nginx: master process /usr/sbin/nginxnginx     37757  37756  0 20:57 ?        00:00:00 nginx: worker processroot      37759   2510  0 20:58 pts/1    00:00:00 grep nginx[root@yangwen ~]# netstat -anpt | grep nginxtcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      37756/nginx         [root@yangwen ~]# curl -I 127.0.0.1HTTP/1.1 200 OKServer: nginx/1.15.6Date: Tue, 20 Nov 2018 12:58:20 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Tue, 20 Nov 2018 12:38:07 GMTConnection: keep-aliveETag: "5bf4002f-264"Accept-Ranges: bytes

[root@yangwen ~]# nginx -Vnginx version: nginx/1.15.6built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) built with OpenSSL 1.1.1  11 Sep 2018TLS SNI support enabledconfigure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log ----pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock ------------user=nginx --group=nginx --with---with---with---with---with---with---with---with---with---with---with---with---with---with-threads --with-stream --with-openssl=/usr/local/src/openssl-1.1.1 --with-stream_ssl_module --with---with-mail --with-mail_ssl_module --with-file-aio --with---with-ipv6注:新版的openssl已经集成到里面了,因此ldd /usr/sbin/nginx | grep ssl不会再显示了

我建议如下命令去操作更安全:./configure xxxmake -j$(nproc)mv /usr/sbin/nginx /usr/sbin/nginx.oldcp -prd objs/nginx /usr/sbin/nginxnginx -s reload

三、证书安全检测

近日,证书爆出的漏洞很多,固然有一部分是历史遗留问题,但是日常运维中我们能有较强的安全意识和扎实的基础知识,也能尽早的发现漏洞并整改,防患于未然。我总结了几种证书漏洞,希望大家集思广益,查缺补漏(证书漏洞查看推荐使用360浏览器)。

2、服务器证书与网址不符   即申请的证书并非适用于本网址,比如网址是oos-nm-iam.ctyunapi.cn,但是证书却是颁发给*.oos-nm.ctyunapi.cn的。

3、证书链不完整。   证书一般是由根证书+中级证书(有的时候不需要中级证书)+网站ssl证书。   证书链不完整主要影响在安卓浏览器,安卓手机上会有提示,但PC浏览器上一般是正常的,有两个方法可以检测。A、linux命令行工具openssl查看   比如查看内蒙资源池api的网址   openssl s_client -connect oos-nm.ctyunapi.cn:443   发现有两个链,如果是一个,就是不完整的表现

B、通过专门的网站查询,我推荐在线网站年 10 月 21 日颁发的证书,这里的证书指的是根证书不合法。比如以360证书为例:

1:根证书,这个不能是沃通证书2:这个是沃通证书,这个没问题,因为这是中间商的证书,不是证书颁发机构3:服务器证书。

第二、证书加密协议以及加密套件     加密协议:     + SSL / TLS,也就是在目前sslv3和sslv2协议已经被破解,不再被推荐使用,所以推荐使用更为安全的TLS协议,一般为tlsv1.2。     加密套件:     当你在浏览器的地址栏上输入Suite(密钥算法套件,后文简称Cipher)[C1,C2,C3, …]发给服务器;服务器接收到浏览器的所有Cipher后,与自己支持的套件作对比,如果找到双方都支持的Cipher,则告知浏览器;浏览器与服务器使用匹配的Cipher进行后续通信。如果服务器没有找到匹配的算法,浏览器(以Firefox 30为例,后续例子中使用的浏览器均为此版本的Firefox)将给出错误信息。

目前支持的加密套件中不支持的有RC4,DH等,所以一般在加密套件里一般去掉这些协议。     目前在各种web服务器配置加密协议和套件不尽相同,在haproxy上配置加密协议和套件如下所示:

ssl-default-bind-options  设置ssl协议一般要禁止sslv3      no-sslv3使用tlsv1.2          force-tlsv12ssl-default-bind-ciphers   设置加密套件一般设置为ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot整合RabbitMQ的5种模式实战
下一篇:光润通智能加密卡 全力守护企业数据信息安全
相关文章

 发表评论

暂时没有评论,来抢沙发吧~