要创建在测试Web应用程序时使用的自签名SSL证书,请按照以下步骤操作:
[req]
default_bits = 2048
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca
prompt = no
[req_distinguished_name]
countryName = Country Name (2 letter code)
countryName_default = US
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = California
localityName = Locality Name (eg, city)
localityName_default = San Francisco
organizationName = Organization Name (eg, company)
organizationName_default = My Company
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = My Department
commonName = Common Name (eg, your name or your server's hostname)
commonName_default = My Server
emailAddress = Email Address
emailAddress_default = myemail@example.com
[req_attributes]
challengePassword = A challenge password
challengePassword_min = 4
challengePassword_max = 20
[v3_ca]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
openssl req -new -newkey rsa:2048 -nodes -keyout privkey.pem -out req.pem
openssl x509 -req -days 365 -in req.pem -signkey privkey.pem -out cert.pem -extfile openssl.cnf -extensions v3_ca
请注意,自签名证书可能会导致浏览器发出警告,因此在实际生产环境中使用时,请确保使用由受信任的证书颁发机构颁发的证书。
领取专属 10元无门槛券
手把手带您无忧上云