Deploy hexo to your personal server
Preamble
Note that you should first make sure that hexo server works fine.
If you haven’t configured hexo before, check this article first:
Build your blog with hexo and deploy to GitHub
You can use hexo to build your own website and blog, and then deploy it using github pages, vercel or some other static website hosting services easily. To increase flexibility and stability for your website, you can also deploy hexo to your server.
Step 1. Init a git repository on the server
Many tutorials will tell you to create a user named ‘git’, disable its shell access, and modify sudoers list. These steps are actually unnecessary. You can directly configure the server with your normal user ($USER).
Create a git repository
In this tutorial, files are placed in /var/www/hexo/ and /var/repo/blog.git, which you can change it to whatever you want, flexibly.
In /var/repo, create an empty git repository blog.git:
1 | |
Configure git-hooks
Edit the file blog.git/hooks/post-update (if it’s not present, create one)
1 | |
and then write the following script to it
1 | |
Then, add executable permission to it:
1 | |
Create /var/www/hexo/ directory and change owner:
1 | |
You can use git clone YourUserName@IP:/var/repo/blog.git to test whether your git and ssh configuration is fine.
After configuring git-hooks, each time you push something to blog.git, it will execute the script, storing contents in /var/www/hexo/.
Step 2: Configure hexo locally
In your local hexo _config.yml, change the ‘deploy’ settings to the follows:
1 | |
If you want to use another git ssh port (port 22 by default), you can use the following:
1 | |
Step 3: Configure nginx on the server
First, make sure nginx is installed and started.
Now the generated static website should be present in the server’s var/www/hexo/ directory. The only thing we need now is to configure nginx, making it pointing to this directory.
Edit the file:
1 | |
and modifying it to
1 | |
Normally you only need to find the line root /var/xxx and modify it.