在亚马逊云Lightsail上部署Ghost博客,并启用CDN

Ghost 是优秀的开源CMS系统,长期保持开源内容管理系统关注度首位。自2013年上线以来,一直保持快速增长,特别是从3.0版本以后,定位更加清晰,为独立出版商提供技术平台。在文本编辑、发布功能完善之后,最近上线了会员、订阅、评论等一系列帮助创作者引流、读沉淀、变现等实用功能。

Ghost 作为开源软件本身不收费,但要把它部署在服务器上,需要支付云资源使用费。Ghost背后的开发商提供一站式托管服务。当然,我们也可以把Ghost部署在自己的服务器上。对于独立创作者而言,流量一般不大,而可选择国内厂家的轻量主机和亚马逊的Lightsail。

Lightsail 包含虚拟主机、数据库、DNS托管、静态IP、CDN等功能,还可以一键部署Wordpres、Ghost等常用网络应用。非常适合中小开发者和意外爱好者。作为Ghost的长期用户,作者也选择把服务器迁移到Lightsail上。为方便有同样需求的爱好者使用方便,特把详细迁移过程记录下来。


  1. 注册亚马逊账号、在Lightsail页面右下角把语言切换为中文,方便操作。
  2. 创建实例,根据个人需求选择实例位置,距离客户群越近越好,选择Ghost镜像,选择付费计划、创建实例。
  3. 在Lightsail首页“联网”中“创建静态IP”选择实例对应区域,创先静态IP地址并绑定到实例上。
  4. 在实例详情页,“联网-IPv4防火墙”中添加入站规则:放通22、80、443、465、587端口。此时,已经可以通过http://ip地址访问站点。
  5. 在实例详情页,下载默认密钥,并记下服务器ip地址和用户名bitnami
  6. 在本地使用命令行终端登录系统。具体参考aws指引。以Mac为例使用以下命令登录服务器。
sudo chmod 400 Lightsail-Key.pem
ssh -i Lightsail-Key.pem bitnami@ip

我们计划使用Lightsail CDN服务,还进行一些额外设置。

⒎Bitnami镜像Ghost站点的默认用户名user@example.com,登录密码通过以下命令获得。

cat bitnami_application_password

⒏通过7获得用户名和密码在过http://ip/ghost登录系统,并在个人账号设置下修改用户名和密码。

⒐配置邮箱服务器,以便发送密码修改、会员通知等。具体参考Ghost设置Mailgun指引。把在mailgun获得的密钥等信息,写入Ghost配置文件config.production.json

cd /opt/bitnami/ghost
sudo vim config.production.json
// config.production.json
"mail": {
  "transport": "SMTP",
  "options": {
    "service": "Mailgun",
    "host": "smtp.mailgun.org",
    "port": 465,
    "secure": true,
    "auth": {
      "user": "发信邮箱",
      "pass": "密码"
    }
  }
},

配置完后,重启Ghost

sudo /opt/bitnami/ctlscript.sh restart ghost

在Ghost后台Setting/Email newsletter中配置Mailgun configuration。根据页面指引获得Mailgun domainMailgun Private API key

⒑设置CDN:在Lightsail首页“联网”中“创建分配”选择实例对应实例作为数据源,缓存行为选择“最适合Wordpress”(aws问题,其他模式无法进行高级缓存设置),选择“不缓存任何内容”,缓存行为先保持默认,在高级缓存设置,编辑“我指定的标头”,设置两个新项目X-Forwarded-Proto / X-Forwarded-For。其他保持不变。

此时,把Ghost后台域名改为自己的网站域名,在config.production.json 中把server修改服务器地址为http://your.domain.com。先设置为http访问,直接设置为https格式,会失败。

cd /opt/bitnami/ghost
sudo vim config.production.json
// config.production.json
"url": "http://your.domain.com",

配置完后,重启Ghost

sudo /opt/bitnami/ctlscript.sh restart ghost

设置ssl:编辑Apache配置,传递在CDN中设置的标头。

sudo vi /opt/bitnami/apache2/conf/httpd.conf

在如下位置添加RequestHeader set X-Forwarded-Proto "https"


    #
    # Avoid passing HTTP_PROXY environment to CGI's on this or
    # backend servers which have lingering "httpoxy" defects.
    # 'Proxy' request header is undefined by the IETF, not list
    #
    RequestHeader unset Proxy early
    RequestHeader set X-Forwarded-Proto "https"

配置完后,重启Ghost

sudo /opt/bitnami/ctlscript.sh restart ghost
sudo /opt/bitnami/ctlscript.sh restart apache
  1. 设置自定义域名。在lightsail 后台CDN配置选择“自定义域名”,如果没有ssl证书,可以直接生成新的ssl证书,域名所有权验证成功后,启用自定义域名。并使用CNAME配置自定义域名与CDN默认域名关联。CDN同步成功后,可通过默认域和自定义域访问站点内容。
  2. config.production.json中把10中配置的url修改为https格式,以确保Member、Subscribe等功能正常使用。
cd /opt/bitnami/ghost
sudo vim config.production.json
// config.production.json
"url": "https://your.domain.com",

配置完后,重启Ghost

sudo /opt/bitnami/ctlscript.sh restart ghost
cd /opt/bitnami/ghost
sudo su ghost -c "ghost update"

镜像为V4.44.0,先升级到V4.48,再升级到V5。

sudo su ghost -c "ghost update v4"
sudo su ghost -c "ghost update v5"

如遇.ghost-cli权限不足,按如下修复

sudo chmod 777 /opt/bitnami/ghost
sudo chown -R ghost:ghost /opt/bitnami/ghost/.ghost-cli
sudo /opt/bitnami/ctlscript.sh restart ghost
sudo /opt/bitnami/ctlscript.sh restart apache

如遇如下升级错误

Knex: run
$ npm install mysql --save
Cannot find module 'mysql'
Require stack:

在ghost 文件夹执行如下命令后,再次升级

sudo npm install mysql --force



cd /opt/bitnami/ghost
sudo chmod 775 content/images
sudo chown sftpuser:sftpuser content/images
sudo /opt/bitnami/ctlscript.sh restart ghost

在Ghost后台测试发布文章功能是否正常,如果遇到

An error occurred.Message: 'EACCES: permission denied, open '/opt/bitnami/ghost/.ghost-cli'' /opt/bitnami/ghost/content/images/2022/09/

需要赋予ghost操作权限。

cd /opt/www/ghost
sudo chmod 777 content/images
sudo chown -R ghost:ghost content/images
sudo /opt/bitnami/ctlscript.sh restart

设置CDN缓存内容。在CDN设置目录和文件覆盖中,添加要缓存的文件和路径,并删除wp-includes和wp-content。一般地,可以缓存以下静态资源。

css|js|jpg|jpeg|gif|ico|png|bmp|pict|csv|doc|pdf|pls|ppt|tif|tiff|eps|ejs|swf|midi|mid|ttf|eot|woff|otf|svg|svgz|webp|docx|xlsx|xls|pptx|ps|class|jar

至此,在亚马逊lightsail上部署Ghost完成。

展开阅读全文

页面更新:2024-04-29

标签:亚马逊   缓存   静态   后台   实例   用户名   密码   服务器   域名   内容   博客

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top