原文链接: https://inote.xyz/lightsail-ghost/
Ghost 是优秀的开源CMS系统,长期保持开源内容管理系统关注度首位。自2013年上线以来,一直保持快速增长,特别是从3.0版本以后,定位更加清晰,为独立出版商提供技术平台。在文本编辑、发布功能完善之后,最近上线了会员、订阅、评论等一系列帮助创作者引流、读沉淀、变现等实用功能。
Ghost 作为开源软件本身不收费,但要把它部署在服务器上,需要支付云资源使用费。Ghost背后的开发商提供一站式托管服务。当然,我们也可以把Ghost部署在自己的服务器上。对于独立创作者而言,流量一般不大,而可选择国内厂家的轻量主机和亚马逊的Lightsail。
Lightsail 包含虚拟主机、数据库、DNS托管、静态IP、CDN等功能,还可以一键部署Wordpres、Ghost等常用网络应用。非常适合中小开发者和意外爱好者。作为Ghost的长期用户,iNote也选择把服务器迁移到Lightsail上。为方便有同样需求的爱好者使用方便,特把详细迁移过程记录下来。
- 注册亚马逊账号、在Lightsail页面右下角把语言切换为中文,方便操作。
- 创建实例,根据个人需求选择实例位置,距离客户群越近越好,选择Ghost镜像,选择付费计划、创建实例。
- 在Lightsail首页“联网”中“创建静态IP”选择实例对应区域,创先静态IP地址并绑定到实例上。
- 在实例详情页,“联网-IPv4防火墙”中添加入站规则:放通22、80、443、465、587端口。此时,已经可以通过
http://ip
地址访问站点。 - 在实例详情页,下载默认密钥,并记下服务器ip地址和用户名
bitnami
。 - 在本地使用命令行终端登录系统。具体参考aws指引。以Mac为例使用以下命令登录服务器。
sudo chmod 400 Lightsail-Key.pem
ssh -i Lightsail-Key.pem [email protected]
我们计划使用Lightsail CDN服务,还进行一些额外设置。
- Bitnami镜像Ghost站点的默认用户名
[email protected]
,登录密码通过以下命令获得。
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": "[email protected]",
"pass": "1234567890"
}
}
},
配置完后,重启Ghost
sudo /opt/bitnami/ctlscript.sh restart ghost
在Ghost后台Setting/Email newsletter中配置Mailgun configuration。根据页面指引获得Mailgun domain
和Mailgun 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"
<IfModule headers_module>
#
# 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"
</IfModule>
配置完后,重启Ghost
sudo /opt/bitnami/ctlscript.sh restart ghost
sudo /opt/bitnami/ctlscript.sh restart apache
-
设置自定义域名。在lightsail 后台CDN配置选择“自定义域名”,如果没有ssl证书,可以直接生成新的ssl证书,域名所有权验证成功后,启用自定义域名。并使用CNAME配置自定义域名与CDN默认域名关联。CDN同步成功后,可通过默认域和自定义域访问站点内容。
-
在
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
- lightsail提供的Ghost镜像版本为4.44.0,现在Ghost已经升级到5.0,如需体验新功能,可进行系统升级。
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
- 迁移老内容到新服务器。现在后台导入备份的json格式内容备份,图片可以使用sftp上传工具上传至对应
content/images
文件夹。上传时,如遇到权限问题。赋予sftp账户操作权限。
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完成。
如需按照官方指导在Ubuntu上安装Ghost,并启用CDN,参考?
本文转自: https://inote.xyz/lightsail-ghost/
本站仅做收录,版权归原作者所有。