2

在AWS lightsail Ubuntu服务器上安装Ghost博客,并启用CDN

 1 year ago
source link: https://inote.xyz/ubuntu-ghost/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在AWS lightsail Ubuntu服务器上安装Ghost博客,并启用CDN

使用Ghost官方推荐方法,在AWS Lightsail Ubuntu主机上安装部署Ghost并配置CDN。

XiYiZhou

Oct 11, 2022 • 2 min read • 13
在AWS lightsail Ubuntu服务器上安装Ghost博客,并启用CDN

在上篇文章在亚马逊云Lightsail上部署Ghost博客,并启用CDN中,我们使用Bitnami封装的镜像把文件把Ghost的部署在了Lightsail上。这次我们使用Ghost官方推荐方法,在AWS Lightsail Ubuntu主机上安装部署Ghost并配置CDN。

  1. 按照Ghost官网的方法How to install Ghost on Ubuntu,正确安装Ghost程序。
  2. 我们打算使用AWS提供ssl证书,在配置SSL环节Do you wish to set up SSL? (Y/n),选n,跳过使用Let’s Encrypt证书。
  3. 设置CDN:在Lightsail首页“联网”中“创建分配”选择实例 对应实例作为数据源,缓存行为选择“最适合Wordpress”(aws问题,其他模式无法进行高级缓存设置),选择“不缓存任何内容”,缓存行为先保持默认,在高级缓存设置,编辑“我指定的标头”,设置两个新项目X-Forwarded-Proto / X-Forwarded-For。其他保持不变。
  4. 配置完成后,使用分配的CDN默认域名访问,我们看到的是nginx默认页面**Welcome to nginx!。**需要让CDN正确获取源站数据,可以删除nginx默认页面的nginx配置文件,并配置域名对应nginx文件。
    a. 删除/etc/nginx/sites-available下default文件
cd /etc/nginx/sites-available

sudo rm -rf default

b. 删除/etc/nginx/sites-enabled下default文件

cd /etc/nginx/sites-enabled

sudo rm -rf default

c. 由于我们的nginx服务,并没有直接面向最终用户,而是在Lightsail CDN后面,并且ssl证书是在CDN上面配置的,导致nginx无法正确获取客户端所使用的协议,从而导致无法将客户端使用的协议传递给ghost。修改nginx配置,强制通知服务使用https协议。

cd /etc/nginx/sites-enabled

sudo vim yourdomain.com.conf
  将`proxy_set_header X-Forwarded-Proto $scheme`修改成`proxy_set_header X-Forwarded-Proto https`
location / {

​    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

​    proxy_set_header X-Forwarded-Proto https;

​    proxy_set_header X-Real-IP $remote_addr;

​    proxy_set_header Host $http_host;

​    proxy_pass http://127.0.0.1:2368;



  }

重启nginx

sudo nginx -s reload

d. 修改ghost配置文件中的URL

cd /var/www/ghost

sudo vim config.production.json
{

 "url": "https://yourdomain.xyz",

 "server": {

  "port": 2368,

  "host": "127.0.0.1"

 },

重新Ghost

ghost restart
  1. 在Lightsail CDN自定义域中启用自定义域名,并在Lightsail CDN中将域名解析到CDN,等待DNS解析生效。
  2. 邮件,文章、图片导入参考上一篇文章。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK