ghost 是一個快速崛起的線上出版平台,使用 node.js 編寫開發,並以 MIT 開放原始碼授權發行,以簡潔、快速、現代感著稱。

時至2019 年,網站早該全面 https 化了,Let's Encrypt 現在已可申請通用字元網域憑證,申請一張 *.example.com 憑證,不管架設的是 www.example.com 或 blog.example.com 都可適用,何況還可用 Certbot docker 輕鬆取得憑證,還沒有 https 憑證的話請參考這篇

docker-compose.yml 如下:

  • 使用官方 ghost:alpine 版本 docker image
  • ghost container內預設使用 port 2368,主機使用 port 8080 對應
  • 使用 environment 變數指定網站 url
  • 網站內容 blog 目錄以 volumes 對應至 container 內的 /var/lib/ghost/content
version: '3.1'

services:
  ghost:
    image: ghost:alpine
    restart: always
    ports:
      - 8080:2368
    volumes:
      - ./blog:/var/lib/ghost/content

執行 docker-compose up -d 後,應可透過 http://localhost:8080  或 http://your-host-ip:8080 確認 ghost 伺服器頁面正確執行。接著來設定 https 反向代理,因為我的伺服器 上已裝有 Apache2,就直接用 Apache2 來做反向代理,改天用 Nginx 時再來加註。另外亦可用 Docker 方式來實作 Apache2 或 Ngnix 的反向代理。

新增 /etc/apache2/sites-available/ghost.conf 內容如下,記得把 example.com 換成自己的網域名稱。

<VirtualHost *:80>

        ServerName ghost.example.com
        ServerAdmin [email protected]

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Redirect permanent / https://ghost.example.com/

</VirtualHost>

<VirtualHost *:443>
        
        ServerName ghost.example.com

        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
        ProxyPreserveHost On

        RequestHeader set X-Forwarded-Proto "https"

</VirtualHost>

在 Debian 中可用 a2ensite ghost 指令,會將 site-available/ghost.conf 以鏈結方式新增至 sites-enable 目錄中,接著再重新載入/啟動 apache2,

systemctl restart apache2

OK! 5 分鐘到~