count ips in nginx

How to Count Unique IPs & Requests per IP in NGINX

If your website is getting a lot of spam visitors or malicious traffic, then it is important to get a count of unique IPs from which your website is getting traffic. It is also important to count requests per IP for each of these IPs in NGINX. In this article, we will look at how to count unique IPs & requests per IP in NGINX.

How to Count Unique IPs & Requests per IP in NGINX

It is quite easy to count uniqie IPs & requests per IP in NGINX.

Open terminal and run the following command.

$ sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr

You will get a list of IP addresses that send most requests along with the number of requests from each ip (to its left).


Also read : How to Host Multiple Domains on One NGINX Server

You can use the same trick on Apache server log also.

Once you have identified the suspicious IP addresses, you can list the requested URLs from each IP using grep command as shown below.

$ sudo cat /var/log/nginx/access.log | grep

That’s it. It is important to track the most frequently visiting IP addresses and keep an eye on the URLs they are requesting to keep your website safe & secure.

Leave a Reply

Your email address will not be published. Required fields are marked *