一、安装 Docker

# 1. 更新系统包
   sudo apt update

# 2. 安装 Docker(如果还没有安装)
   sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
   echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 如果你无法连接上官方源,则使用以下命令
   curl -fsSL https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
   echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.cloud.tencent.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
   sudo apt update
   sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose docker-compose-plugin
   sudo systemctl start docker
   sudo systemctl enable docker

# 3. 验证安装
   docker-compose --version

二、配置 Halo

# 1. 创建Halo目录
mkdir ~/halo

# 2. 配置Halo:
touch ~/halo/docker-compose.yaml

# 3. 更改
nano ~/halo/docker-compose.yaml
# 具体配置参考:
version: "3"

services:
  halo:
    image: registry.fit2cloud.com/halo/halo:2.19
    restart: on-failure:3
    depends_on:
      halodb:
        condition: service_healthy
    networks:
      halo_network:
    volumes:
      - ./halo2:/root/.halo2
    ports:
      - "8090:8090"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s
    command:
      - --spring.r2dbc.url=r2dbc:pool:postgresql://halodb/halo
      - --spring.r2dbc.username=halo
      # PostgreSQL 的密码,请保证与下方 POSTGRES_PASSWORD 的变量值一致。
      - --spring.r2dbc.password=openpostgresql
      - --spring.sql.init.platform=postgresql
      # 外部访问地址,请根据实际需要修改
      - --halo.external-url=http://localhost:8090/
  halodb:
    image: postgres:15.4
    restart: on-failure:3
    networks:
      halo_network:
    volumes:
      - ./db:/var/lib/postgresql/data
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      - POSTGRES_PASSWORD=openpostgresql
      - POSTGRES_USER=halo
      - POSTGRES_DB=halo
      - PGUSER=halo

networks:
  halo_network:

三、启动 Halo

cd ~/halo
sudo docker-compose up -d

四、安装并配置 Nginx

在Ubuntu上安装和配置Nginx可以按照以下步骤进行:

# 安装Nginx
1. 更新系统软件包列表:
    sudo apt update
2. 安装Nginx:
    sudo apt install nginx
3. 启动Nginx服务:
    sudo systemctl start nginx
4. 设置Nginx开机自启动:
    sudo systemctl enable nginx

# 配置Nginx
1. 创建新的虚拟主机:
    如果你需要添加新的虚拟主机,可以在 /etc/nginx/sites-available/ 目录下创建一个新的配置文件,例如 sevenen.cn:
    sudo nano /etc/nginx/sites-available/sevenen.cn
    在新文件中添加虚拟主机配置:
upstream halo {
  server 127.0.0.1:8090;
}
server {
  listen 80;
  listen [::]:80;
  server_name www.sevenen.cn
  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;
  }
}

    然后创建符号链接到 sites-enabled 目录:
    sudo ln -s /etc/nginx/sites-available/sevenen.cn /etc/nginx/sites-enabled/

2. 重新加载Nginx配置:
    每次修改配置文件后,需要重新加载Nginx以应用更改:
    sudo systemctl reload nginx

# 管理Nginx服务

- 查看Nginx状态:
sudo systemctl status nginx

- 停止Nginx服务
sudo systemctl stop nginx

- 重启Nginx服务
sudo systemctl restart nginx

五、配置网站具体内容

访问你配置的网址,登录,就大功告成了。