oneinstack下安装自己的SSL证书

在NGINX上安装自己的SSL证书,这里是用的oneinstack 一键环境安装包,配合的zerossl的免费ssl证书。

 

先添加虚拟机,添加域名:

What Are You Doing?
1. Use HTTP Only
2. Use your own SSL Certificate and Key
3. Use Let’s Encrypt to Create SSL Certificate and Key
q. Exit
Please input the correct option: 2

假设我们要用的域名是 www.hello.com,并且强制把hello.com跳转www.hello.com

然后大致输出:

Your domain: www.hello.com
Virtualhost conf: /usr/local/nginx/conf/vhost/www.hello.com.conf
Directory of: /data/wwwroot/www.hello.com
Rewrite rule: /usr/local/nginx/conf/rewrite/wordpress.conf
Self-signed SSL Certificate: /usr/local/nginx/conf/ssl/www.hello.com.crt
SSL Private Key: /usr/local/nginx/conf/ssl/www.hello.com.key
SSL CSR File: /usr/local/nginx/conf/ssl/www.hello.com.csr

 

oneinstack默认帮我们生成了三个文件,.crt  .key .csr,名字都是www.hello.com。我们需要删除.crt和.key文件,因为我们后面需要用到zerossl提供的文件。

 

安装免费的zerossl为例,官方的三个文件:certificate.crt、ca_bundle.crt 、private.key

我们先先切换到在具体SSL证书目录下( /usr/local/nginx/conf/ssl/),上传上面三个文件,NGINX 需要合并所有 .crt 文件才能允许 SSL 安装,需要运行以下命令才能合并certificate.crt 和ca_bundle.crt 文件。

然后输入:

cat certificate.crt ca_bundle.crt >> www.hello.com.crt (这里输出的.crt文件名称要改成www.hello.com.crt),因为我们前期添加域名的时候自动生成了,不然就要去改hosts文件了。

再把默认的private.key的改成www.hello.com.key。

 

重启NGINX ,/etc/init.d/nginx restart 或者 service NGINX restart。

Leave a reply

Your email address will not be published. Required fields are marked *