search
HomeOperation and MaintenanceNginxNginx access log analysis configuration, real-time monitoring of website access

Nginx access log analysis configuration, real-time monitoring of website access

Jul 04, 2023 am 08:36 AM
nginxreal time monitoringAccess log analysis

Nginx access log analysis configuration, real-time monitoring of website access

Nginx is a high-performance web server and reverse proxy server. Compared with other web servers, it handles static resources and high concurrent requests. It has better performance advantages. For operation and maintenance personnel, it is very important to understand the access status of the website. You can obtain detailed information about access behavior and access sources by analyzing Nginx access logs. This article will introduce how to configure Nginx access log analysis and monitor website access in real time.

First, make sure Nginx is installed correctly and running. Normally, Nginx's access log is located in the /var/log/nginx/access.log file. We can configure Nginx to write logs to specified files and record access information in a predetermined format.

Find the http section in the Nginx configuration file (usually /etc/nginx/nginx.conf) and add the following configuration:

http {
    ...
    
    log_format custom_format '$remote_addr - $remote_user [$time_local] '
                          '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent"';
    
    access_log /var/log/nginx/access.log custom_format;
    
    ...
}

The above code defines a custom log format (custom_format), which includes various fields required to record access information. The specific log format configuration can be adjusted according to actual needs. The access_log directive specifies the path and format of the log file. In this example, we name the log file access.log and use a custom format for recording.

After updating the configuration, you need to restart Nginx to make the configuration take effect:

sudo systemctl restart nginx

Now, Nginx will write the access information in the configured format /var/log/nginx/access .log file. Next, we can use log analysis tools to parse Nginx access logs to better understand website access.

Commonly used log analysis tools include ELK Stack, Awstats, GoAccess, etc. In this article, we will introduce the use of GoAccess to monitor Nginx access in real time.

GoAccess is a real-time log analyzer based on the command line, which can generate intuitive and interactive reports and display the results in HTML format. First, we need to check whether GoAccess has been installed. If not, you can install it through the following command:

sudo apt-get install goaccess

After the installation is complete, we can use the following command to monitor Nginx access in real time:

sudo tail -f /var/log/nginx/access.log | goaccess -a -o /var/www/html/report.html

Among the above commands, tail -f is used to monitor Nginx access log files, and the goaccess command will parse the log in real time and generate a report. The -a flag is used to display all access information, and the -o flag is used to specify the output path of the report. In this example, the report will be stored in HTML format in the /var/www/html/report.html file.

Now, we can view the real-time Nginx access report by accessing http://your_server_ip/report.html through the browser. The report will provide information about the number of visits, access sources, common user agents, HTTP response codes, etc., to help us better understand the access and performance status of the website.

By configuring Nginx access log analysis and real-time monitoring, we can obtain detailed information about website visits in a timely manner. This is very helpful for understanding website performance, troubleshooting abnormal access behavior, and making corresponding optimization adjustments. I hope this article will be helpful to readers who want to learn more about Nginx access log analysis.

The above is the detailed content of Nginx access log analysis configuration, real-time monitoring of website access. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
NGINX and Web Hosting: Serving Files and Managing TrafficNGINX and Web Hosting: Serving Files and Managing TrafficMay 03, 2025 am 12:14 AM

NGINX can be used to serve files and manage traffic. 1) Configure NGINX service static files: define the listening port and file directory. 2) Implement load balancing and traffic management: Use upstream module and cache policies to optimize performance.

NGINX vs. Apache: Comparing Web Server TechnologiesNGINX vs. Apache: Comparing Web Server TechnologiesMay 02, 2025 am 12:08 AM

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.

NGINX and Apache: Deployment and ConfigurationNGINX and Apache: Deployment and ConfigurationMay 01, 2025 am 12:08 AM

NGINX and Apache each have their own advantages, and the choice depends on the specific needs. 1.NGINX is suitable for high concurrency, with simple deployment, and configuration examples include virtual hosts and reverse proxy. 2. Apache is suitable for complex configurations and is equally simple to deploy. Configuration examples include virtual hosts and URL rewrites.

NGINX Unit's Purpose: Running Web ApplicationsNGINX Unit's Purpose: Running Web ApplicationsApr 30, 2025 am 12:06 AM

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX: An Introduction to the High-Performance Web ServerNGINX: An Introduction to the High-Performance Web ServerApr 29, 2025 am 12:02 AM

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.

NGINX vs. Apache: A Look at Their ArchitecturesNGINX vs. Apache: A Look at Their ArchitecturesApr 28, 2025 am 12:13 AM

The main architecture difference between NGINX and Apache is that NGINX adopts event-driven, asynchronous non-blocking model, while Apache uses process or thread model. 1) NGINX efficiently handles high-concurrent connections through event loops and I/O multiplexing mechanisms, suitable for static content and reverse proxy. 2) Apache adopts a multi-process or multi-threaded model, which is highly stable but has high resource consumption, and is suitable for scenarios where rich module expansion is required.

NGINX vs. Apache: Examining the Pros and ConsNGINX vs. Apache: Examining the Pros and ConsApr 27, 2025 am 12:05 AM

NGINX is suitable for handling high concurrent and static content, while Apache is suitable for complex configurations and dynamic content. 1. NGINX efficiently handles concurrent connections, suitable for high-traffic scenarios, but requires additional configuration when processing dynamic content. 2. Apache provides rich modules and flexible configurations, which are suitable for complex needs, but have poor high concurrency performance.

NGINX and Apache: Understanding the Key DifferencesNGINX and Apache: Understanding the Key DifferencesApr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment