Logo Neurocoda

Hexo Webhook Auto-Deployment

Neurocoda
Neurocoda
2026-07-03 12:47:10 439 Words 3 Mins ...

What is Hexo?

Hexo is a fast, simple, and powerful blog framework. Hexo uses Markdown (or other markup languages) to parse articles, and within seconds, beautiful themes are used to generate static web pages.

Environment for this article:

  • A public server
  • A Git platform hosting the site generated by Hexo (Github or self-built Git repository)
  • Ability to run Hexo locally

If you do not have a public server, you can skip the Server Configuration section of this article and instead use other platforms like Github Pages. However, the Local Configuration section remains the same.

Site building approach in this article:

  • Write articles locally, then use Hexo to build the site and push it to a Github repository via git push. After the push ends, Github sends a notification via webhook to my public server, which then automatically clones the site to the directory where Nginx reverse proxy serves the site.

The public server uses the neurocoda/gitrigger:latest container to automate receiving webhook notifications and performing the git clone.

Git Platform Configuration

Create a code repository.

Local Configuration

Install Nodejs

For installation instructions on various systems, see: https://hexo.io/zh-cn/docs/

My local system is Ubuntu:
According to: https://github.com/nodesource/distributions

Terminal window
curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get install -y nodejs

Verify installation:

Terminal window
node -v

Install Hexo-cli

Terminal window
npm install -g hexo-cli

Create Hexo Repository

Terminal window
hexo init <folder>
cd <folder>
npm install

Configure Git

Create an SSH key:

Terminal window
ssh-keygen

Get the public key:

Terminal window
cat /root/.ssh/id_ed25519.pub

Add the obtained public key to your chosen Git platform

Github: https://github.com/settings/keys

Add Git to Hexo

In the Hexo root directory:

Install the plugin:

Terminal window
npm install hexo-deployer-git --save
Terminal window
vim _config.yml

Find the bottom and add repository information:

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: [email protected]:neurocoda/Hexo.git
branch: main

Server Configuration

Firewall Configuration

Open the firewall:

Terminal window
ufw allow 22
ufw allow 80
ufw allow 443

Enable and check firewall status:

Terminal window
ufw enable
ufw status

Install Nginx, Docker

Update sources:

Terminal window
apt update
apt upgrade -y

Install docker-compose, nginx, python3-certbot-nginx:

Terminal window
apt install docker-compose nginx certbot python3-certbot-nginx

Ensure Nginx is running correctly:

Terminal window
systemctl status nginx

Configure SSH Key

If your repository is private, you need to configure an SSH key:

Create an SSH key:

Terminal window
ssh-keygen

Get the public key:

Terminal window
cat /root/.ssh/id_ed25519.pub

Add the obtained public key to your chosen Git platform

Github: https://github.com/settings/keys

Configure Webhook

Configure webhook in the repository:

Start the Service

Create docker-compose.yml:

Terminal window
vim docker-compose.yml

Fill in the following content:

version: '3.8'
services:
hexo:
image: neurocoda/gitrigger:latest
container_name: hexo
restart: unless-stopped
ports:
- "127.0.0.1:7890:5000"
environment:
REPO_URL: "[email protected]:neurocoda/Hexo.git"
volumes:
- /root/.ssh/id_ed25519:/root/.ssh/id_rsa:ro
- /var/www/sites:/clone_data

Execute the up command in the directory where docker-compose.yml is located:

Terminal window
docker-compose up -d

Check container status:

Terminal window
docker ps -a

Status Up means the container is running correctly. (I have other services here, so it may look different)

Check container logs:

Terminal window
docker logs hexo

Configure Reverse Proxy

Edit nginx.conf:

Terminal window
vim /etc/nginx/nginx.conf

Add reverse proxy:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# My Server
##
server {
server_name neurocoda.com;
root /var/www/sites/Hexo;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~* \.(?:css|js|jpg|jpeg|png|gif|ico|svg|webp)$ {
try_files $uri =404;
expires 30d;
add_header Cache-Control "public";
}
error_page 404 /404.html;
location = /404.html {
root /var/www/sites/hexo;
}
}
server {
listen 80;
server_name webhook.neurocoda.com;
location / {
proxy_pass http://127.0.0.1:7890;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
# }

After modifying the configuration, check for syntax errors:

Terminal window
nginx -t

Reload Nginx configuration:

Terminal window
systemctl reload nginx

Ensure DNS records are configured correctly:

Configure SSL

Configure SSL:

Terminal window
certbot --nginx

Follow the prompts to enter information

Check the syntax of the nginx.conf modified by certbot:

Terminal window
nginx -t

Reload Nginx configuration

Terminal window
systemctl reload nginx

Synchronization Test

In your local Hexo directory:

Terminal window
hexo clean & hexo g & hexo d

After execution completes, access your server; hopefully, the web page should be displayed.

Common Issues

Permission Issues

Terminal window
chmod 755 /var/www/sites/Hexo
chown -R www-data:www-data /var/www/sites/Hexo
Title: Hexo Webhook Auto-Deployment Author: Neurocoda Created at: 2026-07-03 12:47:10 Link: https://neurocoda.com/zh-TW/posts/hexo-webhook-auto-deployment-en/ License: This work is licensed under CC BY-ND 4.0.

Comments