Giter Club home page Giter Club logo

nginx-monitor's Introduction

nginx-monitor

To automatically monitor an NGINX server and activate CloudFlare firewall rules according to changes in the rate of active connections. To set it up you will need an API key that has permission to the said cloudflare zone. Edit the first few lines of the script to suit your setup and traffic.

Requirements and dependencies

  • A system running GNU/Linux
  • NGINX (obviously :D)
  • curl
  • jq
  • awk

Setup

Make sure that your NGINX has the http_stub_status_module which is usually enabled by default. You can check whether the modules is enabled via nginx -V | grep --color -o http_stub_status. Once you have that enabled you will need to add this server block to your NGINX config. If done on CentOS just create a file /etc/nginx/conf.d/monitor.conf:

server {
    listen 127.0.0.1:80;
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}

Reload the config with nginx -t && nginx -s reload to apply the new server block. Try to get information from the new server block to see if everything is working curl -s 127.0.0.1/nginx_status. This should show information about current connections to the web server.

Setup your API key and zone ID, adjust the variables according to the amount of traffic that your server gets and just run the script to see if it is working: sh nginx-monitor.sh. If you want to disable logging just leave the variable $LOG empty!

Examples

Since the script takes the running shell it would be a good idea to run it in a detached tmux or screen session. Here some exampels of how you can achieve that.

To run a detached screen session with the script:screen -dmS nginx-monitor sh nginx-monitor.sh

Adding the script to run atomatically on reboot:@reboot screen -dmS nginx-monitor sh nginx-monitor.sh

To attach to the script's session:screen -r nginx-monitor

To detach from the session:CTRL+A+D

To kill the session:CTRL+A+K

Links and additional info

I don't see how this can be further developed but if you have any ideas you are welcome to join my discord and ask for help or give me a heads up for problems with the script.

nginx-monitor's People

Contributors

ivstiv avatar

Watchers

James Cloos 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.