Nginx 兼容IE8

前言

前段時間由於業務需要,在服務器上新增一個服務專門接收各個門店的業務結算數據,接口文檔指明需要使用https協議。這本不是什麼問題,因爲之前服務器已經有配置過https。但等到服務部署之後才發現這些客戶端死活連接不上。一直提示“Error connecting with SSL”的錯誤。服務器明明已經配置好了,而且其它服務使用https協議通信都正常,爲什麼偏偏這些客戶端連接不上呢?

故障排解

windows軟件使用https協議訪問服務器時無法成功連接,通過wireshark發現客戶端軟件所發送的client hello請求所支持的cipher suites的版本比較老舊,而服務器返回handshake failure的提示。

客戶端軟件所發送的握手請求中cipher suites的支持如下:
    Cipher Specs (29 specs)
            Cipher Spec: TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA (0x000016)
            Cipher Spec: TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA (0x000013)
            Cipher Spec: TLS_RSA_WITH_3DES_EDE_CBC_SHA (0x00000a)
            Cipher Spec: TLS_DHE_DSS_WITH_RC4_128_SHA (0x000066)
            Cipher Spec: TLS_RSA_WITH_IDEA_CBC_SHA (0x000007)
            Cipher Spec: TLS_RSA_WITH_RC4_128_SHA (0x000005)
            Cipher Spec: TLS_RSA_WITH_RC4_128_MD5 (0x000004)
            Cipher Spec: TLS_DHE_RSA_WITH_DES_CBC_SHA (0x000015)
            Cipher Spec: TLS_DHE_DSS_WITH_DES_CBC_SHA (0x000012)
            Cipher Spec: TLS_RSA_WITH_DES_CBC_SHA (0x000009)
            Cipher Spec: SSL2_DES_192_EDE3_CBC_WITH_MD5 (0x0700c0)
            Cipher Spec: SSL2_IDEA_128_CBC_WITH_MD5 (0x050080)
            Cipher Spec: SSL2_RC2_128_CBC_WITH_MD5 (0x030080)
            Cipher Spec: SSL2_RC4_128_WITH_MD5 (0x010080)
            Cipher Spec: SSL2_RC4_64_WITH_MD5 (0x080080)
            Cipher Spec: SSL2_DES_64_CBC_WITH_MD5 (0x060040)
            Cipher Spec: TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA (0x000065)
            Cipher Spec: TLS_RSA_EXPORT1024_WITH_RC4_56_SHA (0x000064)
            Cipher Spec: TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA (0x000063)
            Cipher Spec: TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA (0x000062)
            Cipher Spec: TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 (0x000061)
            Cipher Spec: TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 (0x000060)
            Cipher Spec: TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA (0x000014)
            Cipher Spec: TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA (0x000011)
            Cipher Spec: TLS_RSA_EXPORT_WITH_DES40_CBC_SHA (0x000008)
            Cipher Spec: TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 (0x000006)
            Cipher Spec: TLS_RSA_EXPORT_WITH_RC4_40_MD5 (0x000003)
            Cipher Spec: SSL2_RC2_128_CBC_EXPORT40_WITH_MD5 (0x040080)
            Cipher Spec: SSL2_RC4_128_EXPORT40_WITH_MD5 (0x020080)

google資料發現這些加密套件都是很老舊的,有人(https://www.v2ex.com/amp/t/355178)指出,“XP 版本的 IE 8 只支持 SSLv3 和 TLS 1.0 的 Cipher Suite ,另外 nginx 自 1.9.1 開始默認不會開啓 SSLv3”。因此,爲了讓服務器支持像IE8/XP這類客戶端,就不得不重新編譯Nginx,在其中加入支持3DES的參數。

編譯安裝Nginx

依賴工具/庫
dev@ubuntu:~$ sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev unzip git
下載Nginx
dev@ubuntu:~$ wget -c https://nginx.org/download/nginx-1.12.2.tar.gz
dev@ubuntu:~$ tar zxf nginx-1.12.2.tar.gz
查看openSSL版本

本機的openSSL是否支持3DES算法並不影響Nginx是否支持3DES,Nginx是否支持只與它編譯時所使用的openSSL版本有關,從上面的討論中可以知道當前版本的Nginx默認是不支持3DES算法的。而openSSL 1.1.0 以上版本默認不支持也3DES加密。

dev@ubuntu:~$ openssl version
查看openssl是否支持 3DES加密
dev@ubuntu:~$ openssl ciphers -v "3DES" 
下載openssl源

此處的openSSL源碼只是爲了用來編譯Nginx,跟已經安裝在本機上的openSSL沒有任何關係。

dev@ubuntu:~$  wget -O openssl.zip -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_1f.zip
dev@ubuntu:~$  unzip openssl.zip
dev@ubuntu:~$  mv openssl-OpenSSL_1_0_1f/ openssl
編譯安裝Nginx

其中--with-openssl指向openssl源文件 --with-http_ssl_module指明支持ssl 參數--with-openssl-opt指明openssl的選項,其中若要兼容IE8則要添加'enable-weak-ssl-ciphers'。其它的參數可按需配置。
(--with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' 這兩個參數添加之後有時候會報錯)

dev@ubuntu:~$   cd nginx-1.12.2
dev@ubuntu:~/nginx-1.12.2$  ./configure --with-openssl=../openssl --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module  --with-openssl-opt='enable-weak-ssl-ciphers' --with-http_ssl_module
dev@ubuntu:~/nginx-1.12.2$  make
dev@ubuntu:~/nginx-1.12.2$  sudo make install
配置Nginx

下面是Nginx關於SSL/TLS的相關配置。

server {
    listen      443 ssl;
    proxy_set_header X-Real-IP $remote_addr;
    server_name a.example.com;
    ssl_certificate /etc/nginx/cert/cert.pem;
    ssl_certificate_key /etc/nginx/cert/cert.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers EECDH+CHACHA20-draft:EECDH+CHACHA20:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    root        /home/www/html;
    index index.html index.htm;
    location /api {
        proxy_pass http://localhost:8000;
    }
}
                    

參考

https://imququ.com/post/troubleshooting-https.html
https://www.centos.bz/2017/08/nginx-enable-tls-1-3/
https://dyn.im/2016/09/14/21/
https://www.feistyduck.com/library/openssl%2dcookbook/online/
https://www.ssllabs.com/ssltest/analyze.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章