方法一: #DNS验证下载ssl证书 cat certificate.crt、ca_bundle.crt >> server.crt vi server.crt 没有换行符,第二个文件需要在第一个文件的下一行粘贴,否则报错,证书无法使用
cat private.key > server.key
2.ssl.conf listen 443 ssl; servername img.xxx.com;
方法二: #创建根证书 openssl genrsa -des3 -out root.key openssl req -new -key root.key -out root.csr openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt #-------------------- #创建服务器证书 openssl genrsa -des3 -out server.key 2048 #去掉密码 openssl rsa -in server.key -out server.key openssl req -new -key server.key -out server.csr openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crt #server.key and server.crt #=====================
-
创建根证书密钥文件(自己做CA)root.key: openssl genrsa -des3 -out root.key
-
创建根证书的申请文件root.csr:
openssl req -new -key root.key -out root.csr 输出内容为:
[lenin ~]$ openssl req -new -key root.key -out root.csr Enter pass phrase for root.key: ← 输入前面创建的密码 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) [AU]:CN ← 国家代号,中国输入CN State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音 Locality Name (eg, city) []:BeiJing ← 市的全名,拼音 Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名 Organizational Unit Name (eg, section) []: ← 可以不输入 Common Name (eg, YOUR name) []: ← 此时不输入 Email Address []: ← 电子邮箱,可随意填
Please enter the following ‘extra’ attributes to be sent with your certificate request A challenge password []: ← 可以不输入 An optional company name []: ← 可以不输入
-
创建一个自当前日期起为期十年的根证书root.crt:
openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.req -out root.crt
输出内容为:
[lenin[@archer](https://my.oschina.net/archer) ~]$ openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crtSignature oksubject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./emailAddress=admin@mycompany.comGetting Private keyEnter pass phrase for root.key: ← 输入前面创建的密码
#--------- 4. 创建服务器证书密钥server.key:
openssl genrsa –des3 -out server.key 2048
去除key文件口令的命令: openssl rsa -in server.key -out server.key
5.创建服务器证书的申请文件server.csr:
openssl req -new -key server.key -out server.csr
输出内容为:
[lenin[@archer](https://my.oschina.net/archer) ~]$ openssl req -new -key server.key -out server.reqYou are about to be asked to enter information that will be incorporatedinto 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 blankFor some fields there will be a default value,If you enter ‘.’, the field will be left blank.—–Country Name (2 letter code) [AU]:CN ← 国家名称,中国输入CNState or Province Name (full name) [Some-State]:BeiJing ← 省名,拼音Locality Name (eg, city) []:BeiJing ← 市名,拼音Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名Organizational Unit Name (eg, section) []: ← 可以不输入Common Name (eg, YOUR name) []:www.mycompany.com ← 服务器主机名,若填写不正确,浏览器会报告证书无效,但并不影响使用Email Address []:admin@mycompany.com ← 电子邮箱,可随便填Please enter the following ‘extra’ attributesto be sent with your certificate requestA challenge password []: ← 可以不输入An optional company name []: ← 可以不输入
-
创建自当前日期起有效期为期两年的服务器证书server.crt:
openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.csr -out server.crt