搭建个人博客(Ghost)
ghost,blog,docker,docker-compose,nginx,ssl
编写Compose file
version: '3.9'
services:
web:
image: nginx:alpine
restart: always
ports:
- 443:443
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/templates/default.conf.template
- ./ssl:/etc/nginx/ssl
depends_on:
- ghost
- db
ghost:
image: ghost:alpine
restart: always
volumes:
- ./content:/var/lib/ghost/content
environment:
# see https://ghost.org/docs/config/#custom-configuration-files
database__client: mysql
database__connection__host: db
database__connection__user: root
database__connection__password: example
database__connection__database: ghost
# just example
url: https://YOU DOMAIN
db:
image: mysql:8.0
# https://github.com/docker-library/ghost/issues/232
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
配置nginx
server {
listen 443 ssl http2;
server_name YOU DOMAIN;
ssl_certificate_key /etc/nginx/ssl/live/YOU DOMAIN/privkey.pem;
ssl_certificate /etc/nginx/ssl/live/YOU DOMAIN/fullchain.pem;
location / {
# https://ghost.org/docs/faq/proxying-https-infinite-loops/
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;
proxy_pass http://ghost:2368;
}
}
运行
docker-compose up -d
升级
docker-compose pull && docker-compse up -d
数据备份与恢复
# 备份
docker exec db sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > ghost.sql
# 恢复
docker exec -i db sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < ghost.sql