Creating a static website and hosting it has never been easier, thanks to modern web development tools such as Jekyll. Jekyll is a static site generator powered by Ruby that allows you to create fast, secure, and easily maintainable websites. When combined with Nginx, a powerful HTTP server and reverse proxy, you have a powerful and flexible website deployment mechanism. This guide explains how to set up Jekyll with Nginx as a reverse proxy on Debian and Ubuntu systems.
In this tutorial you will learn:
- How to install Jekyll, a popular static site generator, and other necessary software packages on Debian and Ubuntu systems.
- Creating a new Jekyll site.
- Setting up Jekyll as a systemd service, which allows it to start automatically on boot and restart if it crashes.
- Configuring Nginx as a reverse proxy for the Jekyll service. This helps to manage HTTP requests and optimize performance.
- Understanding the importance of running services as a non-root user for enhancing system security.

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | Debian,Ubuntu,Jekyll,Nginx,Git,Ruby,Bundler,systemd |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Step-by-Step Guide
- Install Required Software
First, update your system and install the required software packages:# apt update # apt install ruby-full build-essential zlib1g-dev nginx git -y
Then, install Jekyll and Bundler:
# gem install jekyll bundler
- Create Your Jekyll Site
Create a new Jekyll site by using the command below. Run the command from the directory you wish to host your site from:$ jekyll new mysite
When you run the command
jekyll new mysite
in a terminal, a new Jekyll site will be created in a directory namedmysite
. The location of this directory depends on where you are in your filesystem when you run the command.
For example, if you are in your home directory (/home/yourusername
for a typical user, or/root
for the root user) when you run the command, the site will be located at/home/yourusername/mysite
or/root/mysite
, respectively. - Set Up Jekyll as a Systemd Service
Create a new systemd service file for Jekyll. Make sure that you get theWorkingDirectory
path right as per the step above:# nano /etc/systemd/system/jekyll.service
Then, add the following content:
[Unit] Description=Jekyll Service After=network.target [Service] Type=simple Restart=always RestartSec=1 User=root WorkingDirectory=/home/yourusername/mysite ExecStart=/usr/local/bin/jekyll serve --host 0.0.0.0 --port 4000 [Install] WantedBy=multi-user.target
Finally, enable and start the Jekyll service:
# systemctl enable jekyll # systemctl start jekyll
- Set Up Nginx as a Reverse ProxyRemove the default Nginx configuration:Create a new Nginx configuration file:
# nano /etc/nginx/sites-available/jekyll
And add the following content with a correct
server_name
as your domain name for your new website:[Unit] server { listen 80; listen [::]:80; server_name your-domain-name; location / { proxy_pass http://localhost:4000; 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; } }
Finally, enable the new configuration and restart Nginx:
# ln -s /etc/nginx/sites-available/jekyll /etc/nginx/sites-enabled/ # nginx -t # systemctl restart nginx
- Testing Your Jekyll SiteAfter completing the setup, it’s essential to verify that everything is working as expected. You can test your Jekyll site by visiting your domain in a web browser.In a web browser, navigate to your domain (replace
your-domain-name
with your actual domain):$ wget http://your-domain-name
You should see your Jekyll site load up successfully. If not, make sure your DNS settings are correctly pointing your domain to your server’s IP address, and that Nginx and the Jekyll service are running properly on the server.
Additionally, check the Nginx logs for any error messages that might help you troubleshoot any issues:
# journalctl -u nginx
And the Jekyll service logs:
# journalctl -u jekyll
By following these steps, you can confirm that your Jekyll site is running and accessible via the domain you configured.
Conclusion
By following the steps outlined in this guide, you can successfully set up Jekyll with Nginx as a reverse proxy on your Debian or Ubuntu system. This configuration offers an efficient environment for deploying and managing your static websites.
However, remember that while this setup provides a functioning web service, it’s only accessible via HTTP by default. In today’s digital environment, enhancing the security of your website with HTTPS is paramount. It not only secures the communication between your website and its visitors but also builds trust with your audience and can even improve your site’s SEO. Therefore, configuring Nginx for HTTPS using a trusted SSL certificate is highly recommended for production environments.
Lastly, while running services as a root user might seem easier, it’s advised to run services as a dedicated non-root user for increased system security.