侧边栏壁纸
博主头像
NewTab

记录生活,分享知识

  • 累计撰写 12 篇文章
  • 累计创建 14 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

基于docker的Halo博客搭建(1.6版本)

NewTab
2023-07-24 / 0 评论 / 0 点赞 / 168 阅读 / 704 字 / 正在检测是否收录...
一. 前言

我们将演示 halo 博客 1.6 版本的搭建过程,简单明了、易于上手,1.6版本为Halo的1.x的最后一个版本!

本次搭建基于docker。

二. 准备工作
  1. 域名 可以在万网购买
  2. 服务器 推荐使用搬瓦工,线路优质,无需备案搬瓦工官网
  3. 你需要基本基础的linux知识,比如如何使用ssh连接服务器,基础的vi命令操作,如:wq保存文件

域名购买完成之后,你需要将购买的域名添加A记录指向你购买服务器的ip地址。

三.开始教程

以下的命令基于Debain操作系统,其他操作系统命令基本也差不多。

1. 安装docker
 curl -fsSL https://get.docker.com -o get-docker.sh
 sudo sh get-docker.sh
2. 创建目录
mkdir ~/.halo && cd ~/.halo
3. 新建配置文件
vi application.yaml
4. 输入以下内容
server:
  port: 8090
 
  # Response data gzip.
  compression:
    enabled: false
spring:
  datasource:
 
    # H2 database configuration.
    driver-class-name: org.h2.Driver
    url: jdbc:h2:file:~/.halo/db/halo
    username: admin
    password: 123456 #这个修改成你需要设置的密码
 
  # H2 database console configuration.
  h2:
    console:
      settings:
        web-allow-others: false
      path: /h2-console
      enabled: false
 
halo:
 
  # 后台访问路径为 http://example/admin
  admin-path: admin
 
  cache: memory
5. 安装halo (1.6.1为1.x的最后一个版本,推荐安装)
docker pull halohub/halo:1.6.1
6.启动halo
docker run -it -d --name halo -p 8090:8090 -v ~/.halo:/root/.halo --restart=unless-stopped halohub/halo:1.6.1
7.安装nginx
apt install nginx
8.配置/etc/nginx/nginx.conf (vi /etc/nginx/nginx.conf)
user       www www;

events {
    worker_connections  4096;
}

http {

    default_type application/octet-stream;

	upstream halo {
	  server 127.0.0.1:8090;
	}
	server {
	  listen 80;
	  listen [::]:80;
	  server_name newtab.work;  //此处修改成你的域名
	  client_max_body_size 1024m;
	  location / {
	    proxy_pass http://halo;
	    proxy_set_header HOST $host;
	    proxy_set_header X-Forwarded-Proto $scheme;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	  }
	}
}
9.启动nginx
systemctl start nginx //启动nginx
systemctl stop nginx //停止nginx
systemctl restart nginx //重启nginx
systemctl status nginx //查看nginx的状态
10.如果nginx启动报错,很有可能是www用户没有创建
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www

至此,你就可以通过你的域名访问服务了。

11.https证书配置
安装 certbot 和 certbot nginx 插件

# 根据自己的系统选择相应命令

# CentOS 安装 certbot 以及 certbot nginx 插件
sudo yum install certbot -y
sudo yum install python3-certbot-nginx -y

# Ubuntu 安装 certbot 以及 certbot nginx 插件
sudo apt install certbot
sudo apt install python3-certbot-nginx
12.申请并自动配置证书
sudo certbot --nginx

然后按照提示,输入邮箱 接着输入 a , y, 1, 1 完成

13.自动续约(可选)
sudo certbot renew --dry-run
14.配置halo

进入halo后台->系统 -> 博客设置 -> 博客地址 修改成https即可。

0

评论区