使用Raspberry pi 搭建Ghost博客(docker)
盆友,你猜的没错,本站用的博客就跑在树莓派上。
图样图森破:

看到没,刚创建5小时就迫不及待的发First Post,吼吼吼。
print("Hello World!")
docker
和mysql
的安装就不说了,直接上 docker-compose.yml
version: '3.1'
services:
ghost:
container_name: ghost
image: ghost:latest
restart: always
ports:
- 2368:2368
environment:
# 更改mysql连接信息 (我用的mysql早就装在了nas机器上)
database__client: mysql
database__connection__host: mysql_ip
database__connection__user: db_user
database__connection__password: db_password
database__connection__database: db
# this url value is just an example, and is likely wrong for your environment!
url: https://blog.blobolb.xyz
# contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production
#NODE_ENV: development
volumes:
- /opt/ghost:/var/lib/ghost/content
volumes:
ghost:
创建并启动
sudo docker-compose -f docker-compose.yml up -d
查看日志,确保正常启动
docker logs d7987c282bfa

当然到这里安装完成,如果你要内网用看到这里有可以了。赶紧滚粗。
下面要实现外网访问,并确保访问延迟不能太高。当然成本也要低,毕竟砖挺沉的。
我的方案,首先使用魔法V屁N打通pi和廉价vps(5$),然后nginx反向代理。你也许要问了,为啥不在vps上直接搭建ghost,实在是因为vps存储空间不够了,还不能删,以后在说这上边跑的另一个玩意。
魔法略。。。。
请求经过中间跳转之后,延迟估计要爆表,在加上魔法不稳定,势必会让自己或访问者破防。万幸的是nginx支持cache,经过短期测试,效果杠杠的。下面上nginx配置:
proxy_cache_path /tmp/cache levels=1:2 keys_zone=ghostcache:100m inactive=60m;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
server {
index index.html index.htm index.nginx-debian.html;
server_name blog.blobolb.xyz;
set $skip_cache 0;
if ($request_uri ~* "ghost/|p/|members/") {
set $skip_cache 1;
}
location / {
# Add header for cache status (miss or hit)
add_header X-Cache-Status $upstream_cache_status;
proxy_cache_bypass $skip_cache;
proxy_no_cache $skip_cache;
proxy_cache_valid 1200m;
proxy_cache ghostcache;
# Raspbery pi Ghost魔法地址
proxy_pass http://192.168.196.35:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
client_max_body_size 50m;
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/blog.blobolb.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/blog.blobolb.xyz/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = blog.blobolb.xyz) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name blog.blobolb.xyz;
return 404; # managed by Certbot
}
注意替换Raspbery pi Ghost魔法地址和其他信息。
今天就到这里,过段时间看看稳定性如何。
这句无关紧要的话用来测试nginx cache timeout!!!! 2024-03-14
OK,经测试proxy_cache_valid
好使。2024-03-15
PS.不要忘了备份
Ghost备份数据脚本(备份博客)
小站是跑在家里的树莓派上的,为了peace of mind,把Ghost数据库和重要文件备份到跑unraid的NAS上。 使用Raspberry pi 搭建Ghost博客(docker)盆友,你猜的没错,本站用的博客就跑在树莓派上。 图样图森破: 看到没,刚创建5小时就迫不及待的发First Post,吼吼吼。 print(“Hello World!”) docker和mysql的安装就不说了,直接上 docker-compose.yml version: ‘3.1’ services: ghost: container_name: ghost image: ghost:latest restart: always ports: - 2368:2368 environment: # 更改mysql连接信息 (我用的mysql早就装在了nas机器上) database__client: mysql database__connection__host:
遇到的问题一并列出
Ghost不能加载URL嵌入资源
这个功能貌似叫oembed。简单来说就是当我在嵌入Youtube链接时,不能显示视频预览框,只能纯url显示。 问题提自这里,原因也提了: 没有灵魂的滑板真好玩-周末河边浪玩电动滑板甩了一跤,差点与世长辞。 3月的天气很暖和,桃树已经开花了,但是地还没有绿。 躺下看会书。 自己建的书库也用上了,啊,舒服。 Blobolb | Shelf: ‘本站自用,有朋 + Discord (@gvhi)’发现数千本精彩电子书,涵盖各种题材,从小说到自助书籍一应俱全。免费浏览和下载你喜爱的电子书,随时随地畅享阅读乐趣!BlobolbMatthew McConaughey 一小段视频福利 https://www.youtube.com/watch?v=ytjm2Y5nSGo&ab_channel=ChickChicken 这个链接竟然不能以漂亮的缩略图形式显示,类似下面这样。 使用Raspberry pi 搭建Ghost博客(docker)盆友,你猜的没错,本站用的博客就跑在树莓派上。 图样图森破: 看到没,
Ghost代码高亮
既然是大水码农写博客,免不了贴一些代码片段。 今天我才注意到,Ghost默认不带代码高亮。不过呢,Ghost官方已经给出了方法,而且一下给出了两种。 A complete guide to code snippetsDevelopers write code. Some developers write about writing code. But when they try to share that code on the web, everything that makes code more readable – like formatting and syntax highlighting – is gone!TutorialsTeam Ghost 我选择最简单的第一种。 Done。 Tesing