How to deploy Halo (docker+nginx) on cloud server (Ubuntu)

1. Purchase a cloud server

If you are a student party or have a small pocket, you can recommend Tencent Cloud's lightweight application server, which is relatively cheap and has event discounts

If you have money, you can consider buying a cloud server. Although it is more expensive, the user experience is better

I have used both Alibaba Cloud (trial) and Tencent Cloud's lightweight application servers, and finally deployed on Tencent Cloud's 2-core 4G6M lightweight application server

2. Connect to the server

After purchasing the server, reset the instance password and check the public network ip

Use cmd or ssh client to connect to the server

You can pass the ssh command:

ssh 用户名@公网ip  #用户名阿里云是root,腾讯云是ubuntu

Then enter the password you just set to connect

Or create a new connection directly in the ssh client

3. Download docker

Execute the following commands in sequence

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce

Tencent Cloud's lightweight application server will be relatively slow, which can be accelerated by continuous ctrl+c and sudo apt-get -y install docker-ce (I do this myself)

mirror acceleration

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://wh5nhpj4.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

4. Deploy Halo using a Docker image

Refer to Halo official documentation

1. Create a directory

mkdir ~/.halo && cd ~/.halo

2. Download the sample configuration file to the working directory

wget https://dl.halo.run/config/application-template.yaml -O ./application.yaml

3. Edit the configuration file, configure the database or port (skipable)

vim application.yaml

4. Pull the latest Halo image

1.5.4 is the version number

docker pull halohub/halo:1.5.4

You can also pull the following command

docker pull halohub/halo:latest

This step of Tencent Cloud Lightweight Application Server will be slower

5. Create the container

The port can be modified, here is port 8090

docker run -it -d --name halo -p 8090:8090 -v ~/.halo:/root/.halo --restart=unless-stopped halohub/halo:1.5.4

After completing this step, you can http://ip:端口号visit the installation page by visiting

Remember to open the corresponding port in the server in advance. Tencent Cloud is in the firewall, and Alibaba Cloud is in the security group.

5. Configure nginx

If you want to access the blog through your own domain name, you can configure nginx to achieve it

The domain name is best purchased from the same cloud service provider

The server needs to be a yearly and monthly subscription, and the fee-based one cannot pass the ICP record

Install

sudo apt-get install nginx

configuration

According to the official document configuration, modify the following code and put it under the http block in /etc/nginx/nginx.conf

upstream halo {
  server 127.0.0.1:8090;  		#修改为自己的ip和端口号
}
server {
  listen 80;
  listen [::]:80;
  server_name www.yourdomain.com;	#修改为自己的域名
  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;
  }
}

Log out these two lines of code in /etc/nginx/nginx.conf, otherwise the default configuration will be used

#	include /etc/nginx/conf.d/*.conf;
#	include /etc/nginx/sites-enabled/*;

Tencent Cloud users need to change the first line to the root user, otherwise an error will be reported

user root;

You can modify the file through ssh or sftp, or you can download it locally for modification, and then download it to the corresponding location on the server through github

Overload configuration

nginx -t
nginx -s reload

restart nginx

systemctl restart nginx

6. Configure cloud DNS resolution

Configure cloud DNS resolution on the cloud server website

7. ICP filing and public security filing

Complete ICP filing and public security filing on the cloud server website and the national public security agency Internet site security management service platform

After the record is completed, add the record number at the bottom of the website

After the record is completed, you can access the website through your own domain name (ICP will be blocked by the cloud server provider before the record is completed, and can only be accessed through ip)

Guess you like

Origin blog.csdn.net/qq_53570748/article/details/127250084