依古法產生自簽憑證,
在Firefox測試正常,也有綠色勾勾。
但是在Chrome就失敗了,打開DEVTOOL的Security項目看到以下有紅色三角型。
Subject Alternative Name Missing
Certificate Error(net::ERR_CERT_COMMON_NAME_INVALID)
Secure Connection
Google後發現了一些眉角,以下從頭講一次解法。
nginx.conf 設定:
找到 listen 80;
在下面加入以下設定:
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/www.crt;
ssl_certificate_key /etc/nginx/ssl/www.key
憑證產生設定檔:
req.conf
[req]
distinguished_name=req_distinguished_name
req_extensions=v3_req
[req_distinguished_name]
commonName=*.local.asus
organizatiionUnitName=EC
organizationName=ASUS
localityName=Taipei
stateOrProvinceName=Taiwan
countryName=TW
[v3_req]
keyUsage=keyEncipherment,dateEncipherment
extendedKeyUsage=serverAuth
subjectAltName=@alt_names
[alt_names]
DNS.1=www-us1.local.asus
DNS.2=shop-us1.local.asus
產生 Root 憑證
#openssl genrsa -des3 -out RootCA.key 4096
#openssl req -new -sha256 -key RootCA.key -out RootCA.req
#openssl x509 -req -days 3650 -sha256 -signkey RootCA.key -in RootCA.req -out RootCA.crt
產生Server 憑證
#openssl genrsa -out server.key 2048
#openssl req -new -sha256 -config req.conf -key server.key -out server.req
#openssl x509 -req -days 3650 -sha256 -extensions v3_req -extfile req.conf -CA RootCA.crt -CAkey RootCA.key -CAserial RootCA.srl -CAcreateserial -in server.req -out server.crt
產生nginx 用憑證
#cp server.crt www.crt
#cat RootCA.crt >> www.crt
*SHA-2
*SAN(Subject Alternative Name)
將根憑證 RootCA.crt 分別匯入Firefox與Chrome。
參考:
產生self signed SAN 憑證(只參考 req.conf)