自定义生成SSL证书

1.创建证书存放路径

mkdir /home/nginx/conf/cert

2.切到该路径下

cd /home/nginx/conf/cert

3.生成根证书的私钥

openssl genrsa 2048 > /home/nginx/conf/cert/server.key
#genrsa:产生rsa密钥命令
#2048: 密钥的长度位数,默认为512
#一开始我创建的长度是1024,但是应用在Nginx上的时候报错,后来查了资料,不同的Linux系统对于长度要求不同,后来改成了2048

4.生成证书签署请求,(创建服务器证书的申请文件server.csr)

openssl req -new -key /home/nginx/conf/cert/server.key > /home/nginx/conf/cert/server.csr

会出现提示填写信息

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN    #国家名称
State or Province Name (full name) []:JS  #州或省名称
Locality Name (eg, city) [Default City]:NJ    #城市
Organization Name (eg, company) [Default Company Ltd]:XXX  #组织名称(例如,公司)
Organizational Unit Name (eg, section) []:XXX      #组织单位名称(例如,部门)
Common Name (eg, your name or your server's hostname) []:XXX      #通用名称(例如,您的名称或服务器主机名)
Email Address []:XXX    #电子邮件地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:XXX   #密码
An optional company name []:XXX    #可选公司名称

5.创建服务器证书

openssl req -x509 -days 3650 -key /home/nginx/conf/cert/server.key -in /home/nginx/conf/cert/server.csr > /home/nginx/conf/cert/server.crt

6.查看生成的证书
会发现/home/nginx/conf/cert目录下
存在三个文件:server.crt server.csr server.key

本文转载参考:

1.nginx生成ssl证书

posted @ 2022-12-07 15:17  rachel_zh  阅读(1259)  评论(0)    收藏  举报