Use Hugo and alicloud ECS to build personal stations

The personal station has been using Hexo before. After a long time, on the one hand, it is aesthetic fatigue. On the other hand, there are more and more articles, and the generation is slower and slower under Hexo, so it is considered to migrate to Hugo this weekend

On the whole, it is relatively smooth, but most of the websites are built under githubPage, and few use personal servers, so simply record it

Local configuration

1 install Hugo

follow Official documents Just come, for example, I'm under the mac

brew install hugo
2. Station construction

Simple, one line command. For example, if I want to build a site in the local directory / home/Mysite, I can replace path with this directory

hugo new site path
cd path
3 installation theme

Clone is a topic configuration. You can directly clone or add git sub modules. Note that you can enter the root directory of the site in the previous step. For example, I choose papermod

Directly clone to the / themes/PaperMod path in the root directory of the site

git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1
cd themes/PaperMod
git pull

Finally, modify the theme configuration under config.yaml. The. toml configuration file may be obtained after the site is built. It depends on my personal preference. I am used to writing yaml, so I directly convert the format

theme: "PaperMod"

At this point, the local station will be completed without any difficulty

hugo server -D

You can preview directly

Server configuration

The next step is to introduce less server configuration on the Internet

1 ssh into your server
ssh root@XXX.XXX.XX.XX
2. Establish git user
sudo adduser git
3 install git
sudo apt install git
4. Create a new git warehouse on the server

Note that the Github warehouse is not built here, but the git warehouse on your own server

  • Create a warehouse hugo.git under the GIT directory
  • At the same time, a folder hugo is established to store the warehouse files
su git
cd /home
mkdir git
cd git
git init --bare hugo.git
sudo chown -R git:git hugo.git
mkdir hugo
5 configuration hook
vim /home/git/hugo.git/hooks/post-receive

Write the following text

git --work-tree=/home/git/hugo --git-dir=/home/git/hugo.git checkout -f

Configure permissions

sudo chmod +x /home/git/hugo.git/hooks/post-receive
6 configure Nginx

Installing Nginx

sudo apt install nginx

Modify Nginx configuration file

vim /etc/nginx/sites-available/default

Just change one place and change the root path from / var/www/html to the newly established / home/git/hugo where the warehouse file is stored

Restart service

service nginx reload
service nginx restart
7 configure SSH public key

Generate locally first

ssh-keygen -t RSA -C "usr mailbox"
cat .ssh/id_rsa.pub

Then copy the cat content to. SSH / authorized on the server_ Keys file

mkdir .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
vim .ssh/authorized_keys

So far, all the configuration of the server has been completed. If any of the above operations prompt that something is missing, sudo apt install

Deploy to local server

1 configuration file

Change the baseURL in the config file of the local website to its own domain name

baseURL: "https://wonghaotian.com/"
2 domain name resolution

Go to the place where you buy the domain name and resolve your domain name to your server ip

This specific Baidu

3 deployment

Run locally

hugo

After the command, a public folder is generated in the root directory of the website, which contains static web page files. push the whole public folder into the hugo.git warehouse we just configured on the server

Remote git warehouse address format

git@[The server IP]:[hugo.git route]

If you strictly follow the steps I just said, it should be:
git@XXX.XXX.XX.XX:/home/git/hugo.git
cd public
git init
git add .
git commit -m 'First Commit'
git remote add origin git@XXX.XXX.XX.XX:/home/git/hugo.git
git push -u origin master

If everything goes well, your personal hugo site has been successfully deployed on the ECS. You can access the domain name to display it

Welcome to my station tiiaan

Keywords: git Alibaba Cloud blog hugo

Added by webwannabee on Sun, 31 Oct 2021 22:56:58 +0200