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

  1. Install NGINX (if not already installed):

    bash

    sudo apt update

sudo apt install nginx


  1. Create a new NGINX configuration file or modify the default:

    bash
    sudo nano /etc/nginx/sites-available/static-site


  1. 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;

     }

}


  1. 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

  1. Create a New Jenkins Freestyle Project.

  2. In Source Code Management, select Git and enter the GitHub repository URL.

  3. In the Build Triggers section, enable “Poll SCM” or “GitHub hook trigger for GITScm polling” for automated builds.


  1. Add a Build Step:
    Select "Execute Shell" and add:

    bash
    git pull origin main

cp -r * /var/www/static-site/

  1. Adjust File Permissions (Optional):

    bash
    sudo chown -R www-data:www-data /var/www/static-site

sudo chmod -R 755 /var/www/static-site

  1. 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

Popular posts from this blog

ECS Deployment Best Practices: Blue/Green with CodePipeline and CodeDeploy

Creating BI Solutions: AI/BI Genie Space Authoring Best Practices in Databricks

AWS Console Not Loading? Here’s How to Fix It Fast

YouTube Channel