Historical archive
Deploying a Hexo Blog with Git and Nginx
Notes from rebuilding a personal blog as a Hexo static site, deploying it through a bare Git repository, and serving it over HTTPS with Nginx.
My previous dynamic blog ran on a free AWS server. I did not renew it and eventually lost the data. Since my needs were modest, rebuilding the site as a static blog was the simpler choice.
Install and run Hexo locally
See the Hexo documentation for the current setup instructions.
npm install hexo-cli -g
hexo new page categories
hexo new page tags
hexo s
Install hexo-deployer-git, then configure _config.yml:
deploy:
type: git
repo: root@121.196.197.46:blog.git
Deploy the generated site:
hexo d
Prepare the server
Install Git and Nginx:
apt-get install git-core nginx
Create a bare remote repository:
mkdir ~/blog.git
cd ~/blog.git
git init --bare
Create blog.git/hooks/post-receive. The hook runs whenever the repository receives a push:
#!/bin/bash
rm -rf /var/www/blog
git clone /root/blog.git /var/www/blog
Configure Nginx
The first server block redirects HTTP traffic to HTTPS. The second serves the generated static files and enables TLS and gzip compression.
server {
listen 80;
server_name blog.artifact4u.com;
rewrite ^(.*)$ https://blog.artifact4u.com permanent;
}
server {
listen 443;
server_name blog.artifact4u.com;
ssl on;
ssl_certificate cert/blog.artifact4u.com.pem;
ssl_certificate_key cert/blog.artifact4u.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
root /var/www/blog;
access_log /var/log/access_log;
error_log /var/log/error_log;
client_max_body_size 1m;
gzip on;
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_types text/css application/x-javascript application/json;
sendfile on;
}
This configuration reflects the original 2019 deployment. Review current TLS and Nginx recommendations before reusing it in production.