Automated Deployment of a Static Website from GitHub Using Jenkins and NGINX
Overview
This guide outlines the process of deploying a static website hosted on GitHub using Jenkins for continuous integration and NGINX as the web server. By automating this workflow, developers can ensure seamless updates to their website every time changes are pushed to the repository.
Prerequisites
Before getting started, ensure the following are installed and configured:
Jenkins
Git
NGINX
A GitHub repository containing the static website files
Web server with root or sudo access
Step 1: Configure NGINX for Static Website Hosting
Install NGINX (if not already installed):
bash
sudo apt update
sudo apt install nginx
Create a new NGINX configuration file or modify the default:
bash
sudo nano /etc/nginx/sites-available/static-site
Example NGINX config:
nginx
server {
listen 80;
server_name your_domain.com;
root /var/www/static-site;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable the configuration and restart NGINX:
bash
sudo ln -s /etc/nginx/sites-available/static-site /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Step 2: Set Up Jenkins Job for Deployment
Create a New Jenkins Freestyle Project.
In Source Code Management, select Git and enter the GitHub repository URL.
In the Build Triggers section, enable “Poll SCM” or “GitHub hook trigger for GITScm polling” for automated builds.
Add a Build Step:
Select "Execute Shell" and add:
bash
git pull origin main
cp -r * /var/www/static-site/
Adjust File Permissions (Optional):
bash
sudo chown -R www-data:www-data /var/www/static-site
sudo chmod -R 755 /var/www/static-site
Build the Project:
Click "Build Now" to trigger the deployment.
Step 3: Verify Deployment
Visit http://your_domain.com to verify that the static website is live and updated.
Check Jenkins logs for any build errors or issues.
Conclusion
This setup provides a streamlined DevOps workflow for deploying static websites using Jenkins and GitHub, with NGINX handling the web server role. With automated builds and deployments, updates become seamless and efficient, significantly reducing manual intervention.

Comments
Post a Comment