利用Caddy部署Hugo博客

通过Gitea和Caddy实现Hugo自动部署

Gitea和Caddy服务

version: '2.1'
services:
  git:
    image: gitea/gitea
    container_name: git
    volumes:
    - ./gitdata:/data
    network_mode: host
    restart: always
  caddy:
    image: spanda/caddy
    container_name: caddy
    volumes:
    - ./ssl:/root/.caddy
    - /var/log/caddy:/var/log/caddy
    - ./Caddyfile:/etc/Caddyfile
    - /root/.ssh:/root/.ssh
    - /www:/www
    - /pkg:/pkg
    network_mode: host
    restart: always

Caddy配置文件

ysicing.me www.ysicing.me {
    gzip
    prometheus
    log / /var/log/caddy/ysicing.me.log "{remote} {when} {method} {uri} {proto} {status} {size} {>User-Agent} {latency}" {
   	rotate_size 50
	rotate_age  90
	rotate_keep 20
	rotate_compress
    }
    tls root@ysicing.net
    header / {
    	Strict-Transport-Security "max-age=31536000;includeSubDomains;preload"
    	Access-Control-Allow-Origin  *
	    Access-Control-Allow-Methods "GET, POST, OPTIONS"
    	X-XSS-Protection "1; mode=block"
	    X-Content-Type-Options "nosniff"
	    X-Frame-Options "SAMEORIGIN"
	    -Server
	}
    errors {
        * /tmp/404.html
    }
    root /tmp/blog/public
    git {
        repo git@repo.spanda.io:ysicing.me/website.git
        path /tmp/blog
        branch master
        key      /root/.ssh/id_rsa
        then hugo --destination=/tmp/blog/public
        hook /webhook GiteaSK
        hook_type gogs
        clone_args --recursive
        pull_args --recurse-submodules
        interval 86400
    }
    hugo
    redir 301 {
        if {host} starts_with www
        /   https://ysicing.me{uri}
    }
}

具体说明可以参考Caddy中文使用指南

其他

有点困了,抽空在补一下。

推荐阅读