Hexo Webhook Auto-Deployment
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:latestcontainer 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
curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.shsudo -E bash nodesource_setup.shsudo apt-get install -y nodejsVerify installation:
node -vInstall Hexo-cli
npm install -g hexo-cliCreate Hexo Repository
hexo init <folder>cd <folder>npm installConfigure Git
Create an SSH key:
ssh-keygenGet the public key:
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:
npm install hexo-deployer-git --savevim _config.ymlFind the bottom and add repository information:
# Deployment## Docs: https://hexo.io/docs/one-command-deploymentdeploy: type: git branch: mainServer Configuration
Firewall Configuration
Open the firewall:
ufw allow 22ufw allow 80ufw allow 443Enable and check firewall status:
ufw enableufw status
Install Nginx, Docker
Update sources:
apt updateapt upgrade -yInstall docker-compose, nginx, python3-certbot-nginx:
apt install docker-compose nginx certbot python3-certbot-nginxEnsure Nginx is running correctly:
systemctl status nginx
Configure SSH Key
If your repository is private, you need to configure an SSH key:
Create an SSH key:
ssh-keygenGet the public key:
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:
vim docker-compose.ymlFill 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: volumes: - /root/.ssh/id_ed25519:/root/.ssh/id_rsa:ro - /var/www/sites:/clone_dataExecute the up command in the directory where docker-compose.yml is located:
docker-compose up -dCheck container status:
docker ps -a
Status Up means the container is running correctly. (I have other services here, so it may look different)
Check container logs:
docker logs hexo
Configure Reverse Proxy
Edit nginx.conf:
vim /etc/nginx/nginx.confAdd 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:
nginx -t
Reload Nginx configuration:
systemctl reload nginxEnsure DNS records are configured correctly:

Configure SSL
Configure SSL:
certbot --nginxFollow the prompts to enter information

Check the syntax of the nginx.conf modified by certbot:
nginx -tReload Nginx configuration
systemctl reload nginxSynchronization Test
In your local Hexo directory:
hexo clean & hexo g & hexo dAfter execution completes, access your server; hopefully, the web page should be displayed.
Common Issues
Permission Issues
chmod 755 /var/www/sites/Hexochown -R www-data:www-data /var/www/sites/Hexo