刚刚安装完的这个Ghost Blog实际上是没有办法留评论的,因为任何评论系统都还没有Set up。网上找到的各种资料基本上也都是集成一个第三方的平台,比如 Disqus,或者 Github 之类的。不过Ghost现在有了自己原生的Member支持,处于简单考虑,就用原生的就好。
但是原生的这个系统依赖邮件验证,这中间就至少需要能够发送邮件。官方推荐的是Mailgun的系统。但是,again,对于一个简单的个人博客,实在是过于繁琐了(贵)。
Docker Compose的部署方式,默认的Mail方式是Direct。这等于用sendmail 这个binary。Ghost Docker的Host,因为什么都没设置,sendmail自然不可能工作。
可是没想到的是,这种情况下 Ghost 本身不会报错。Log里面也空空如也。用户 Sign up或者 Sign in的时候,直接就 hang 住了,没有任何反馈。
这也就是为什么花了一段时间才明白过来是Mail的问题。
所有的Config都在 /var/lib/ghost/config.production.json 里面。
- 因为在 Docker compose YAML 里面相当于设定的是 PRODUCTION env。所以这里用的是 production json。其实此时 config.development.json 也是一个 symbolic link pointing to the production json.
- Add the “mail” section in the json, with information including: transport,host,port,auth.user,auth.pass。注意这里的auth.pass,如果用的是Gmail的话,需要是APP password,而不是平时个人登陆的使用的密码。通常是一串16个小些字符的字符串。
Example JSON content
{
  "url": "http://localhost:2368",
  "server": {
    "port": 2368,
    "host": "::"
  },
  "mail": {
    "transport": "SMTP",
    "options": {
      "service": "Google",
      "host": "smtp.gmail.com",
      "port": 587,
      "auth": {
        "user": "YourGmail@gmail.com",
        "pass": "xxxxxxxxxxxxxxxx"
      }
    }
  },
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/lib/ghost/content"
  }
}这里其实有点意思,因为这里的 url 显示的还是 localhost。然而实际上在Docker Compose YAML 里面我以及给了这个博客的网址。看来这个Environment Variable 并没有写进这个JSON。
同时,这里的 mail 的内容也是可以在 Docker Compose YAML 里面给定的,效果应该一样的。应该是用下面这些 environment variable:
- mail__transport
- mail__from
- mail__options__service
- mail__options__host
- mail__options__port
- mail__options__auth__user
- mail__options__auth__pass
这部分细节确实没有在官方文档中看到。也算是从网上搜刮来的。
设定完成之后需要重启 Ghost,再尝试 Sign up Sign in 就正常了。
关于Gmail 的 App password的获取,主要是这么几步:
- 
确保你的账户已经打开了2-step verification。登陆https://myaccount.google.com/ 查看并打开两步验证。  
- 
然后搜索栏里面直接搜 App Passwords,就会引导你创建一个 App Password  
如果提供的密码或者用户名(就是那个Email地址全称)错误,在 Log 里会报错。