使用Docker搭建Ghost应用

目录结构

- ghost目录
  - data		// 数据库存放目录
  - logs		// 日志目录
  - content		// 存放 ghost 的内容目录
  - docker-compose.yml	// docker-compose 配置
  - nginx		// nginx 相关配置
    - default.conf	// web 服务器配置
    - ssl		// 存放 https 证书
      - xxx.key
      - xxx.pem

docker-compose 配置

version: '3.1'
services:
  web:
    image: nginx:latest
    restart: always
    depends_on:
      - ghost
    volumes:
      - "./nginx:/etc/nginx/conf.d"
      - "./logs:/var/log/nginx"
    ports:
      - "80:80"
      - "443:443"

  ghost:
    image: ghost:latest
    restart: always
    depends_on:
      - db
    volumes:
      - ./content:/var/lib/ghost/content
    environment:
      url: https://yuuji.cn
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: example
      database__connection__database: ghost

  db:
    image: mysql:5.7
    restart: always
    volumes: 
      - ./data:/var/lib/mysql
    environment:
      MYSQL_USER: root
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: ghost

nginx 配置

server {
    listen       80;
    listen       443 http2;
    server_name  yuuji.cn www.yuuji.cn;

    charset utf-8;

    ssl on;
    ssl_certificate      conf.d/ssl/xxx.pem;
    ssl_certificate_key  conf.d/ssl/xxx.key;

    error_page 497 https://$host$request_uri;

    location / {
        proxy_pass http://ghost:2368;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}