About https x509 error

問題描述

今天更新 SSL 憑證時發現在 Docker 中運行的網站做 SSL 驗證時會出現 x509 錯誤 certificat signed by unknown authority,這是因為 Docker 中對照的 Root CA 不是最新的,需要手動把 Root CA 加入到信任的 CA list中,即可解決。

解決方法

  1. 先下載最新的 Root CA,可以到 sslchecker查找。
    下載後用文字編輯器打開,稍後複製其內容,會長得像這樣:

    1
    2
    3
    4
    5
    6
    -----BEGIN CERTIFICATE-----  
    MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYD
    ......
    ......
    +O7AWXX1uw16OFNMQkpw0PlZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3pQ==
    -----END CERTIFICATE-----
  2. 在 Docker 運行的伺服器中執行以下指令,查看目前信任的 CA list 檔案位置。

    1
    $ curl https://yourdomain.com -v

    我這邊得到的是 CAfile: /etc/pki/tls/certs/ca-bundle.crt,依照你的 OS 不同會有所不同。

  3. 將步驟 1 的內容貼到檔案最後面,並儲存。

    1
    $ sudo vi /etc/pki/tls/certs/ca-bundle.crt
  4. 重新啟動 Docker。

    1
    2
    $ cd ~/<your docker app folder>
    $ docker compose restart

    我們是使用 docker compose 來運行 Docker,所以使用 docker compose restart 來重啟 Docker,如果你是使用 docker run 的話,可以使用 docker restart <container name> 來重啟 Docker。

Hello World

非常推薦使用 hexo + github pages 來架設個人靜態網站,步驟相當簡單,本機安裝 hexo,使用 hexo cli 指令產生一個工作目錄,接著在 github 上建立一個 repository,然後本機再多裝一個 hexo-deployer-git 的套件,設定好 config 檔的 depo 設定,最後在本機的工作目錄中執行 hexo deploy 指令,就可以將網站部署到 github 上了。
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment