nginx 配置中间证书

一般 nginx 配置 https ,只要两个证书就可以了,但是有时候有一个中间证书的东西,也是和外面的公司对接才知道,具体配置如下:

 server {
        listen       443 ssl;

        server_name  xxx.xxx.com;

        #rewrite ^(.*)$ https://$host$1;

        ssl_certificate      /usr/local/nginx/certs/xxx.xxx.com-2021.crt;
        ssl_certificate_key  /usr/local/nginx/certs/xxx.xxx.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}

        location / {
            root   /var/www/html/;
            index  index.html index.htm;
        }

假如你已经有以下3个文件:
服务器证书:xxx.xxx.com.crt

key 文件:xxx.xxx.com.key

中间证书:xxx.ca_xxx.crt

来到 linux 存放文件的目录,使用命令

cat xxx.xxx.com.crt xxx.ca_xxx.crt >> xxx.xxx.com-2021.crt

会自动在当前目录生成一个 xxx.xxx.com-2021.crt 新的合并好的证书,之后只需要替换到 

ssl_certificate      /usr/local/nginx/certs/xxx.xxx.com-2021.crt;

里面就可以了,然后重启 nginx 即可!
也可以下载下来,使用 notepad 打开两个证书,手动把中间证书的内容 copy 到 服务器证书下面,然后保存为一个新的证书,但是我自己试过,不成功,可能是有空格什么的,所以建议用命令比较好
原文地址:https://www.cnblogs.com/xuehuashanghe/p/14554856.html