rsync to deploy my website for the past few days, but it seemed that there were some bugs with
hexo rsync deployment, I could only use rsync by running
rsync -a localfiles username@server:/remote/path manually instead of simply
hexo deploy. Instead of looking for the reason why
rsync doesn’t work in hexo, I decided to set up a git server for deployment, because git provides an extra version control feature, which might come in handy sometime in the future. It actually took me a lot of time to do this because there were little information on the Internet regarding it, so writing a blog to record this process is important, I think.
First we need to set up an nginx on the server, I use
centos, so the command works for me
If you are using ubuntu, the following command would work for you
When the installation finishes, start your nginx
You can test whether
nginx works or not by typing in your server’s IP address on your client.
To set up a git server, the first thing we need to do is to create a username for it, let’s call it
git, you should run this command on your server.
It will prompt you for a password.
To avoid typing in the password every time we use
git, we need to set up a ssh key pair. Run the command on your client.
enter when a prompt shows up. Then you will find a file called
.ssh folder of your home directory, this is the public key. Now turn to the server, switch your username to git.
.ssh foler in your git home directory
create a file named
authorized_keys to save the accepted public keys
Now turn to your client side, run the following command to add your client’s public key to your server, notice that you should replace the IP address with yours.
Change the permissions to avoid others modifying your ssh key pair
OK, the next time you log on to your server with the user name
git, you won’t need the password anymore. Now Let’s turn to the server side and set up a bare local repository
Now turn to your client, go to the hexo directory, install hexo-deployer-git
Then find the
_config.yml file and open it. Add the following lines at the end of the file. Notice that you should replace the IP address with your server’s. If there is other deployment setting in your file like this, please remove it.
Let’s use git to sync our website to the server
If nothing error occurs, you’re successful till now.
Now that you’ve synced your website to the server, but you cannot find these files on your server, why? In fact, it took me a lot of time to search for my website in the
website.git folder, but I just couldn’t find it. After gleaning information on the Internet, I realized that my website is still on my server, but not in the way it is stored on my client. Those website files are stored as the
object in the
git bare repository, you cannot see those files, but you can
So what we need do is deploy these synced files to our web server’s root directory. Go to your nginx’s root directory (it’s usually
/usr/share/nginx/html, but I noticed that it’s
/var/www/html on ubuntu 15.10), set up a git repository and add the remote server(localhost, actually)
git user the permission to modify our website, we need to change the ownership of those files to
Set up the git hook for deployment, it will automatically sync your files from
/usr/share/nginx/html every time it receives a
Then set the permission to make the git hook work.
To avoid the authorization issue, add the public key of
root to the
authorized_keys of user
OK, now we are ready to go. Turn to the client side and deploy your files with hexo-git-deployer
Then check your website on your server.
This is a long story for me. So there might be something that I didn’t mention, or you get confused about something in the post. If so, please leave a comment below to let me know, I’d like to help you.