Nginx 配置了基于 IP 的自签名证书后,原本配置的基于域名的证书失效

2020-02-24 18:21:22 +08:00
 watara

因业务需要,先需要给 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 的提示是 同时这时候查看网站状态,发现并没有证书信息。 而 Chrome 下的提示是下图,总之都是说我的证书不安全就是了。

搜索的时候参考了很多文档,比如 ququ 大神的这篇文章,还有其他,基本上确定应该是和 http2 有关,我把配置里面的 http2 去掉后,也确实可以打开网站了,但浏览器都提示说我的网站不安全,使用了脆弱的加密方式,如下图。 问题是我并没有使用图片里的加密方式,也并没有使用 TLSv1.0。 同时 nginx 的日志里显示已经正确的把 222 状态返回给了客户端。 我对问题的探索的进度基本上到此为止了,我的一些想法是:

突然想到一点,如果我把 firefox 的about:config里的network.http.spdy.enabled.http2设置为 false,就可以打开网站,网址栏锁头标志上提示不安全,其中的详情和图 4 里的详情是一模一样的。 所以,有前辈大神遇到过此类问题吗?或者有相关思路呢?

4794 次点击
所在节点    NGINX
24 条回复
kof21411
2020-02-25 19:04:55 +08:00
开启 ip https 的访问默认的话,会封掉除该 ip 之下的所有正常域名的 https 访问
AlphaWu
2020-02-25 20:55:04 +08:00
@kof21411 不会的,我已经测试了,都正常,IP 的 https 可以访问,IP 之下的其他域名的 https 都可以正常访问。
watara
2020-02-25 21:23:44 +08:00
@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 相关文件以及上述到两个配置文件。
keyfunc
2020-02-26 09:55:36 +08:00
@watara TLS1.3 协议要 Openssl1.1.1 以后才支持,你压根不支持 1.3,估计 nginx 直接调默认配置了,按道理你启动肯定有警告信息的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/647171

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX