Nginx 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
- 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.
- 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.
- 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".
