:::info 视频演示 https://www.bilibili.com/video/BV1534y1X7Q3/ :::
说明
key 文件
公钥或者私钥,并非X.509证书
查看
openssl rsa -in mykey.key -text -noout
csr
证书签名请求,这个并不是证书,而是向权威证书颁发机构获得签名证书的申请
查看
openssl req -noout -text -in my.csr
crt/cert/pem
证书文件
查看
openssl x509 -in certificate.pem -text -noout
生成证书
定义域名
domain=hub.haifengat.com
生成 crt 根证书
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 36500 -subj "/C=CN/ST=ShangHai/L=ShangHai/O=example/OU=Personal/CN=${domain}" -key ca.key -out ca.crt
生成 csr 签名请求文件
openssl genrsa -out ${domain}.key 4096
openssl req -sha512 -new -subj "/C=CN/ST=ShangHai/L=ShangHai/O=example/OU=Personal/CN=${domain}" -key ${domain}.key -out ${domain}.csr
生成 crt/cert 证书
cat > v3.ext << EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=${domain}
EOF
openssl x509 -req -sha512 -days 36500 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in ${domain}.csr -out ${domain}.crt
openssl x509 -inform PEM -in ${domain}.crt -out ${domain}.cert
配置 nginx
修改 nginx.conf
hub.haifengat.com.key
hub.haifengat.com.cert
重启服务
docker-compose restart
客户端认证
创建认证目录
mkdir -p /etc/docker/certs.d/hub.haifengat.com
复制 ca.crt 文件
- docker 登录
docker login -u admin -p Harbor12345 hub.haifengat.com