环境准备
利用 OpenSSL 签发证书需要 OpenSSL 软件及库,一般情况下 CentOS、Ubuntu 等系统均已内置, 可执行openssl
确认,如果提示 oepnssl: command not found
,则需手动安装,以Centos为例:
yum install openssl openssl-devel -y
生成证书请求文件
新建openssl.cnf,内容如下:[req] distinguished_name = req_distinguished_name req_extensions = v3_req [req_distinguished_name] countryName = Country Name (2 letter code) countryName_default = CH stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = GD localityName = Locality Name (eg, city) localityName_default = ShenZhen organizationalUnitName = Organizational Unit Name (eg, section) organizationalUnitName_default = organizationalUnitName commonName = Internet Widgits Ltd commonName_max = 64 [ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [alt_names] # 改成自己的域名 #DNS.1 = kb.example.com #DNS.2 = helpdesk.example.org #DNS.3 = systems.example.net # 改成自己的ip IP.1 = 172.16.24.143 IP.2 = 172.16.24.85
生成私钥
10.0.11.17.key 为最终生成的文件名,一般以服务器命名,可改。
openssl genrsa -out 10.0.11.17.key 2048
创建CSR文件
创建CSR文件命令:
openssl req -new -out 10.0.11.17.csr -key 10.0.11.17.key -config openssl.cnf
执行后,系统会提示输入组织等信息,按提示输入如即可。
测试CSR文件是否生成成功,可以使用下面的命令:
openssl req -text -noout -in san_domain_com.csr //执行后,会看到类似如下的信息: Certificate Request: Data: Version: 0 (0x0) Subject: C=US, ST=MN, L=Minneapolis, OU=Domain Control Validated, CN=zz Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit)
自签名并创建证书
openssl x509 -req -days 3650 -in 10.0.11.17.csr -signkey 10.0.11.17.key -out 10.0.11.17.crt -extensions v3_req -extfile openssl.cnf
执行后,可看到本目录下多了以下三个文件 san_domain_com.crt
san_domain_com.csr
san_domain_com.key
至此,使用openssl生成证书已完成,可以将证书导入nginx验证证书是否生效。
标签:10.0,centos,证书,ip,req,openssl,key,11.17 From: https://www.cnblogs.com/RiverRiver/p/18228234