Git Product home page Git Product logo

nginx_install's Introduction

Nginx + Modsecurity

These sripts are used for installing High Availability Nginx + Modsecurity in Debian/Ubuntu (Active + Active)

Prerequisites

  • Load Balancer
  • 2 Virtual Machines (Debian/Ubuntu) attached to the Load Balancer
  • Mounted NFS on both Nginx VMs that is storing these Folders (/mnt/nginx-config, /mnt/letsencrypt, /mnt/ssl-acme)

Installation

sudo apt update && sudo apt upgrade
  • Install Nginx

Note: If you are going to install nginx/modsec on the second Nginx VM please comment out these configs in /etc/nginx/nginx.conf before executing the script for installing nginx/modsec otherwise you will face error on when you are installing nginx/modsec:

  • load_module modules/ngx_http_modsecurity_module.so;
  • modsecurity on;
  • modsecurity_rules_file /etc/nginx/modsec/rules.conf;
sudo bash nginx_install.sh
  • Install modsec
bash modsec_nginx_install.sh
  • Copy nginx.conf
sudo mv /etc/nginx/nginx.conf{,.bak}
sudo cp ./nginx.conf /etc/nginx/nginx.conf
  • Change the remote IP on this script (on 1st Nginx change it with the IP of the 2nd Nginx, on 2nd Nginx change it with the IP of the 1st Nginx :
sudo vim /usr/sbin/inotify_nginx.sh
sudo supervisorctl restart all
  • Check nginx config & reload nginx service:
sudo nginx -t && sudo systemctl reload nginx
  • Generate SSH key for root user (it's used for reloading nginx on remote NGINX by inotify-wait service when there is new change of nginx configs and letsencrypt SSL cert)
sudo ssh-keygen
sudo cat /root/.ssh/id_rsa.pub
  • add the content of /root/.ssh/id_rsa.pub to the remote nginx in file /root/.ssh/authorized_keys
  • test the ssh: sudo ssh remote_nginx_ip
  • create DNS API secret for certbot (in this example I use Gandi)
sudo mkdir -p /etc/letsencrypt/.secrets
echo "dns_gandi_api_key=API-KEY-FROM-HERE" | sudo tee gandi.ini

How to Upgrade Nginx

  • Create a backup/snapshot of the VM
  • Backup folder /etc/nginx
sudo rsync -avz /etc/nginx/ /etc/nginx_bak_$(date +%Y%m%d)/
  • Upgrade modsec using the upgrade script from the repo, we need to know first the destination of the nginx version that we want to upgrade to, it's needed to compile the modsec
bash modsec_nginx_upgrade.sh NEW-NGINX-VERSION (ex: 1.21.0)
  • Upgrade Nginx
sudo apt update
sudo apt upgrade nginx​​​​​​​
nginx -v
sudo nginx -t
sudo systemctl status nginx
  • do the same on another NGINX VM

Authors

nginx_install's People

Watchers

James Cloos avatar risman_sr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.