search
HomeOperation and MaintenanceNginxNginx log analysis and HTTP/HTTPS security audit practice

With the continuous development of the Internet, network security issues have received more and more attention. As an IT practitioner, log analysis and security auditing are one of the skills we must master. In this article, we will focus on how to use the Nginx log analysis tool to conduct HTTP/HTTPS security audit practices.

1. Nginx log analysis

Nginx, as a high-performance web server, provides rich logging functions. The Nginx log file is located in the /usr/local/nginx/logs/ directory, and access.log is the access log we use most often.

Nginx access log formats are very rich, the common formats are as follows:

$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"

Among them, $remote_addr represents the client's IP address, $remote_user represents the user's name, $time_local represents the access time, $ request represents the request content, $status represents the response status, $body_bytes_sent represents the number of bytes sent, $http_referer represents the reference source, $http_user_agent represents the client's User Agent, and $http_x_forwarded_for represents the IP address of the proxy server.

Through the analysis of Nginx access logs, we can understand the user's access path, request type, client type, return status code and other information, which provides a favorable basis for subsequent security audits.

2. HTTP/HTTPS security audit practice

  1. Monitor HTTP requests

The network is filled with a large number of malicious requests, such as SQL injection and XSS attacks Etc., these attacks often use HTTP to deliver harmful data. By analyzing Nginx access logs, we can discover these malicious requests in time, and then intercept and prevent them.

We can monitor HTTP requests through Nginx configuring the log format and log path. The common configuration methods are as follows:

log_format monitor '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
access_log  /usr/local/nginx/logs/monitor.log monitor;

In this way, we can output the log to the monitor .log file to facilitate subsequent analysis.

  1. Monitoring HTTPS requests

The encrypted transmission mechanism of HTTPS makes malicious requests more difficult to detect. We need to use more sophisticated log analysis methods to monitor HTTPS requests. .

Nginx provides logs of the SSL handshake and certificate verification process. We can enable these logs by configuring ssl_protocols and ssl_ciphers. Common configuration methods are as follows:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

# 开启SSL握手和证书验证日志
ssl_session_tickets off;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /usr/local/nginx/conf/cert/ca.pem;
ssl_certificate /usr/local/nginx/conf/cert/server.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/server.key;
ssl_session_log /usr/local/nginx/logs/ssl_session.log;

Among them, ssl_session_log enables SSL handshake and certificate verification logs, and the logs can be output to the ssl_session.log file to facilitate subsequent analysis.

  1. Monitor access sources

Network attacks often use HTTP Referer or HTTP User Agent to deceive the server and obtain illegal permissions. Therefore, we need to monitor access sources in a timely manner to prevent malicious access.

We can use Nginx to configure the access_log log format and log path to monitor access sources. The common configuration methods are as follows:

log_format referer '$remote_addr [$time_local] "$request" "$http_referer" "$http_user_agent"';
access_log /usr/local/nginx/logs/referer.log referer;

In this way, we can combine Referer and User Agent outputs to the referer.log file for subsequent analysis.

4. Summary

Nginx log analysis and HTTP/HTTPS security audit practices can improve network security prevention capabilities and help us discover and handle security vulnerabilities and malicious requests in a timely manner. Through the configuration method introduced in this article, we can easily monitor HTTP and HTTPS requests and analyze the access source. I hope everyone can make good use of these tools in actual work and improve their safety level.

The above is the detailed content of Nginx log analysis and HTTP/HTTPS security audit practice. 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
Using NGINX Unit: Deploying and Managing ApplicationsUsing NGINX Unit: Deploying and Managing ApplicationsApr 22, 2025 am 12:06 AM

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX vs. Apache: A Comparative Analysis of Web ServersNGINX vs. Apache: A Comparative Analysis of Web ServersApr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX Unit's Advantages: Flexibility and PerformanceNGINX Unit's Advantages: Flexibility and PerformanceApr 20, 2025 am 12:07 AM

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor