- 应用了 Halo 开源博客零碎,因为是 Java 实现的,不便本人做定制,顺便学习源码
- 联合应用 Docker Compose 实现服务搭建
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- 如果呈现网络问题,间接用浏览器下载可执行文件放到
/usr/local/bin
目录下即可
mkdir -p /root/blog/halo && mkdir -p /root/blog/nginx/ \
echo 'server {
listen 80;
server_name blog.demoli.xyz;
rewrite ^(.*)$ https://blog.demoli.xyz$1 permanent;
}
location / {
proxy_pass http://halo:8090;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
}
}' >> /root/blog/nginx/nginx.conf
- 证书能够从阿里云收费申请,绑定到对应的域名即可,并搁置到
/root/blog/nginx/
目录下(能够自在批改,留神与下边的 yaml 文件保持一致即可)
cd /root/blog/halo && wget https://dl.halo.run/config/application-template.yaml -O ./application.yaml
version: '3.1'
services:
nginx:
image: nginx
container_name: nginx
restart: unless-stopped
ports:
- 443:443
- 80:80
volumes:
- /root/blog/nginx/nginx.conf:/etc/nginx/conf.d/blog.conf
- /root/blog/nginx/blog.demoli.xyz/:/etc/nginx/ssl/
halo:
image: halohub/halo
container_name: halo
restart: unless-stopped
volumes:
- /root/blog/halo:/root/.halo' >> /root/blog/blog.yaml
- 只须要在域名提供商,为本人购买的域名,增加 A 类型的子域名记录比方
blog.demoli.xyz
,而后将解析值设置为本人服务器的公网 IP 即可
docker-compose -f blog.yaml up -d
- 拜访域名即可
- 数据备份(重要):
cp -r ./halo ./halo.archive
- 关停服务:
docker-compose -f blog.yaml down
- 更新镜像:
docker pull halohub/halo
- 重启服务:
docker-compose -f blog.yaml up -d
- Traefik 是云原生时代与 Docker、K8s 都能配合应用的新一代网关产品,可应用 Traefik 代替 Nginx,参考 Treafik 学习的案例篇章
- 举荐开启两步验证的登录形式,安全性高一点,能够在用户设置中增加