:::info 视频演示 https://www.bilibili.com/video/BV1534y1X7Q3/ :::

说明

key 文件

公钥或者私钥,并非X.509证书

查看

  1. openssl rsa -in mykey.key -text -noout

csr

证书签名请求,这个并不是证书,而是向权威证书颁发机构获得签名证书的申请

查看

  1. openssl req -noout -text -in my.csr

crt/cert/pem

证书文件

查看

  1. openssl x509 -in certificate.pem -text -noout

生成证书

定义域名

  1. domain=hub.haifengat.com

生成 crt 根证书

  1. openssl genrsa -out ca.key 4096
  2. 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 签名请求文件

  1. openssl genrsa -out ${domain}.key 4096
  2. 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 证书

  1. cat > v3.ext << EOF
  2. authorityKeyIdentifier=keyid,issuer
  3. basicConstraints=CA:FALSE
  4. keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
  5. extendedKeyUsage = serverAuth
  6. subjectAltName = @alt_names
  7. [alt_names]
  8. DNS.1=${domain}
  9. EOF
  10. openssl x509 -req -sha512 -days 36500 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in ${domain}.csr -out ${domain}.crt
  11. openssl x509 -inform PEM -in ${domain}.crt -out ${domain}.cert

配置 nginx

修改 nginx.conf

hub.haifengat.com.key
hub.haifengat.com.cert

重启服务

  1. docker-compose restart

客户端认证

  1. 创建认证目录

    1. mkdir -p /etc/docker/certs.d/hub.haifengat.com
  2. 复制 ca.crt 文件

  3. docker 登录
    1. docker login -u admin -p Harbor12345 hub.haifengat.com