因业务需要,先需要给 IP 配置自签名的证书,配置完后发现原本可以的网站打不开了,这个场景太少了,搜索了一天无果,问了几个朋友页没有头绪。所以上论坛来请教一下各位大神。 先贴上配置文件,下面这个是原本正常的网站配置文件domain.conf
。
server { listen 80; server_name www.domain.com; return 301 https://www.domain.com$request_uri; } server { #listen 443 ssl; listen 443 ssl; server_name www.domain.com; access_log /data/logs/www.log main; add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; ssl_certificate /etc/nginx/ssl/fullchain.cer; ssl_certificate_key /etc/nginx/ssl/fullchain.key; ssl_dhparam /etc/nginx/dhparam.pem; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; ssl_protocols TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft: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; return 222; }
下面是基于 IP 的自签名证书的配置文件ipssl.conf
:
server { listen 443 ssl http2; server_name 192.168.200.136; root /tmp/webroot/ip; index index.html; access_log /data/logs/ip_access.log; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; ssl_session_timeout 5m; ssl_protocols SSLv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; }
ipssl.conf
的时候,网站是可以正常打开的,但加了以后就打不开了,而且不同浏览器的提示不一样,Firefox 的提示是 搜索的时候参考了很多文档,比如 ququ 大神的这篇文章,还有其他,基本上确定应该是和 http2 有关,我把配置里面的 http2 去掉后,也确实可以打开网站了,但浏览器都提示说我的网站不安全,使用了脆弱的加密方式,如下图。 问题是我并没有使用图片里的加密方式,也并没有使用 TLSv1.0。 同时 nginx 的日志里显示已经正确的把 222 状态返回给了客户端。
我对问题的探索的进度基本上到此为止了,我的一些想法是:
突然想到一点,如果我把 firefox 的about:config
里的network.http.spdy.enabled.http2
设置为 false,就可以打开网站,网址栏锁头标志上提示不安全,其中的详情和图 4 里的详情是一模一样的。 所以,有前辈大神遇到过此类问题吗?或者有相关思路呢?
刚准备脱敏打包的时候顺手又修改了一下配置文件,设置了一下,从线上服务器上把ssl_protocols
和ssl_ciphers
改了下,结果发现都正常了。后续又加上了http2,还是正常的。
下面是我改版后的配置文件。修改过的只有ssl_protocols
和ssl_ciphers
两个地方,但具体为啥,还是不理解。
server { listen 80; server_name www.domain.com; return 301 https://www.domain.com$request_uri; } server { listen 443 ssl http2; server_name www.domain.com; add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; ssl_certificate /etc/nginx/ssl/fullchain.cer; ssl_certificate_key /etc/nginx/ssl/fullchain.key; ssl_dhparam /etc/nginx/dhparam.pem; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256:ECDHE+3DES:RSA+3DES; return 222; }
ipssl.conf:
server { listen 443 ssl http2; server_name 192.168.200.136; root /tmp/webroot/ip; index index.html; access_log /data/logs/ip_access.log; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; ssl_session_timeout 5m; ssl_prefer_server_ciphers on; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256:ECDHE+3DES:RSA+3DES; }
1 Kobayashi 2020-02-24 19:11:04 +08:00 ![]() 我就想知道你 SSLv1.2 是怎么加进去的?这不启动报错吗? |
![]() | 3 Citrus 2020-02-24 20:44:38 +08:00 ![]() @watara 你的参考文章已经说明了,是 ssl_ciphers 的关系,那么你有尝试过修改这个配置么?结果呢? 另外你说在去掉 http2 之后协商出了 TLS1.0,那么我觉得,你需要检查一下你的配置。注意,ssl_protocols 并不是一个真正的 per server 的配置,而是一定程度上是一个 per instance 的配置哦。 |
![]() | 4 zhizunzz 2020-02-24 20:58:35 +08:00 via Android ![]() 巧了,最近看到个库[mkcert]( https://github.com/FiloSottile/mkcert)可以很方便的生成并安装证书,你看下能不能用哈,不懂这方面 |
6 watara OP |
7 dorothyREN 2020-02-24 22:49:56 +08:00 单主机 多 https 配置会有问题。只有第一个能正常访问 |
![]() | 8 keyfunc 2020-02-24 23:30:24 +08:00 ![]() 可以做以下尝试 1. ssl_prefer_server_ciphers on; 设置为 off 2. ssl_protocols TLSv1.3; 调整为 TLSv1.2 TLSv1.3 3. ssl_ciphers 做下调整 ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 简单分析一下,楼主可以使用 openssl ciphers -V 命令查看服务端支持所有的 CipherSuite, TLS13-XXX 这种写法我印象中已经从 openssl 已经移除了,所以你配置中的所有 1.3 的 CipherSuite 全是无效的,另外你启用了 ssl_prefer_server_ciphers,所以你配置里第一个可用的 CipherSuite 就是 RSA+AES128,被降级到 TLS1.0 很正常。 另外我还怀疑楼主的 Openssl 版本压根不支持 TLS1.3 .......... SSL 的配置可以使用 Mozilla 提供的 SSL Configuration Generator [https://ssl-config.mozilla.org/] 工具生成配置文件,比较推荐。 |
9 watara OP @keyfunc #8 感谢,说实话我感觉和 ssl_ciphers 没关系,我做过这些尝试,也用过 Mozilla wiki 里推荐的设置,情况是一样的,这里最重要的一点还是 ip_ssl.conf 里配置,如果我把这个配置文件移除了,一切正常,但把这个加入进去,就不行了,和研发领导讨论了下,换方案的了,改接口,用常规域名+常规证书请求。 |
![]() | 10 keyfunc 2020-02-24 23:41:37 +08:00 https://202.96.220.171/ https://wiki.shca-inc.com/ 和你需求类似的示例,同一台主机,IP 配置了张自签的证书,域名使用 LE 的证书,理论上肯定是没问题的。 也是 nginx |
![]() | 12 keyfunc 2020-02-24 23:54:03 +08:00 SSH 端口外网访问不到,我们周三上班,不着急的话周三可以发给你。但是我还是觉得是你 ssl_ciphers 配置有问题。 |
![]() | 13 msg7086 2020-02-25 04:21:22 +08:00 via Android 多个 SSL 区都做自己的 SSL 设定,感觉很不靠谱啊,不考虑统一一下并拉到上一层吗? 另外 tls1.3 的 cipher 并不能这么设置的。 |
14 kof21411 2020-02-25 08:22:24 +08:00 楼主你要明白 https 通讯的原理,简单来说就是 ip 是优先过域名的,如果你要 ip 和域名同时使用,那只能两个独立 ip 而域名不能绑在要开通 https 的 ip 之下 |
15 watara OP |
![]() | 16 stefanaka 2020-02-25 10:06:49 +08:00 via Android @kof21411 ip 访问默认会给 default_server 处理,一般为了应对恶意解析,会封掉除了正常域名访问之外的其他请求,对吗? |
17 2kCS5c0b0ITXE5k2 2020-02-25 12:00:54 +08:00 开多一个 ip 吧 |
![]() | 18 Citrus 2020-02-25 16:33:08 +08:00 @watara 能否提供一个可用的最小完整配置复现这个问题?比如,把你 /etc/nginx 下所有的文件脱敏后上传一下。这样我们可以尝试搭建一个环境看看能不能复现你的问题。另外以防万一最好也提供一下 nginx 和 openssl 的版本。 |
20 watara OP |
21 kof21411 2020-02-25 19:04:55 +08:00 开启 ip https 的访问默认的话,会封掉除该 ip 之下的所有正常域名的 https 访问 |
23 watara OP @Citrus #18 @kof21411 #14 @keyfunc #12 @dorothyREN #7 @zhizunzz #5 @Kobayashi #1 修改了下配置文件后可以了,具体配置详见 append,然后这里补充一下我的环境吧。 系统:CentOS Linux release 7.7.1908 nginx 是直接用 yum 直接一键安装的,具体的版本是 nginx/1.16.1,具体详情如下: ``` [root@localhost conf.d]# nginx -V nginx version: nginx/1.16.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' ``` nginx 主配置文件没进行修改过,仅仅是添加了 ssl 相关文件以及上述到两个配置文件。 |