Using rsync to Deploy Your Jekyll Site
When you locally build your site with Jekyll, you end up with a finished generated site in the _site
folder that you can simply upload to your web host.
But instead of using SFTP to do this, we’ll be making it a little fancier. Let’s assume you have your host ready and can SSH into it.
Deploying to a VPS
The following script will use rsync
to mirror your local folder to your remote server. rsync
is quite intelligent in doing so, only transferring the changed portions of your site on subsequent commits.
Make sure to edit the variables above. Note: rsync
will in fact wipe the destination folder clean and only leave the mirrored content there so double-check the path.
I have had issues with wrong permissions on files and folders on the destination host, so you might want to adjust permissions at the target location. This requires a newer version of rsync
that’s not available on a default installation of macOS.
Simply install a more current version of rsync
with:
The user-installed version should automatically get priority.
The script will attempt to change permissions on files and folders accordingly.
If your sshuser
is unprivileged—he definitely shouldn’t be root—, make sure that the content in your web root is owned by him, the group can stay at www-data
or whichever group your web server belongs to. The script will also leave hidden files and directories alone and not change or delete them, ensuring compatibility with the web root functionality of letsencrypt
.
Other methods
Check out other methods of Jekyll deployment.
Please write to hi@tobyx.com for comments and questions.