How can you check server traffic with nginx?

To check the traffic of nginx, you can use the following method:

  1. search for a specific pattern in a file
  2. You only need one choice, which is “word count.”
  3. the access log for nginx stored in the directory /var/log/nginx
grep -c '' /var/log/nginx/access.log
  1. Utilize third-party tools like GoAccess or AwStats to analyze Nginx access logs. These tools can provide more detailed statistics such as visit frequency, unique visitors, and traffic sources. You will need to install and configure these tools, and import the log files into their statistical analysis.
  2. Employ the ngx_http_stub_status_module in NGX. Initially, enable this module in the nginx configuration file, then access the specific URL to view the statistics. For instance, assuming you added the following configuration in the file:
location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
}

Next, you can check the statistics of nginx by visiting http://localhost/nginx_status, which includes total number of requests, active connection numbers, and more.

Please note that the methods above are only applicable for viewing current or historical traffic. If you want to monitor nginx traffic in real time, you may consider using monitoring tools such as Prometheus and Grafana for better visualization and analysis of data.

bannerAds