通过查看Nginx的并发连接,我们可以更清除的知道网站的负载情况。Nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过web界面,一种是通过命令,web查看要比命令查看显示的结果精确一些。
下面介绍这两种查看方法
No1、通过浏览器查看
通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 --with-http_stub_status_module 然后配置Nginx.conf,在server点里面加入如下内容
location /status { stub_status on; access_log /usr/local/nginx/logs/status.log; auth_basic "NginxStatus"; }
解析:
Active connections //当前 Nginx 正处理的活动连接数。 server accepts handledrequests //总共处理了8 个连接 , 成功创建 8 次握手,总共处理了500个请求。 Reading //nginx 读取到客户端的 Header 信息数。 Writing //nginx 返回给客户端的 Header 信息数。 Waiting //开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接
No2、通过命令查看
#netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
解析:
CLOSED //无连接是活动的或正在进行 LISTEN //服务器在等待进入呼叫 SYN_RECV //一个连接请求已经到达,等待确认 SYN_SENT //应用已经开始,打开一个连接 ESTABLISHED //正常数据传输状态/当前并发连接数 FIN_WAIT1 //应用说它已经完成 FIN_WAIT2 //另一边已同意释放 ITMED_WAIT //等待所有分组死掉 CLOSING //两边同时尝试关闭 TIME_WAIT //另一边已初始化一个释放 LAST_ACK //等待所有分组死掉
相关文章推荐:
1.PHP中常见的Nginx日志以及配置的方法
2.怎么分析nginx的错误日志
相关视频推荐:
1.燕十八nginx精品视频教程
nginx访问量统计
1.根据访问IP统计UV
awk '{print $1}' access.log|sort | uniq -c |wc -l
2.统计访问URL统计PV
awk '{print $7}' access.log|wc -l
3.查询访问最频繁的URL
awk '{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more
4.查询访问最频繁的IP
awk '{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more
5.根据时间段统计查看日志
cat access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more
查找访问频率最高的 URL 和次数:
cat access.log | awk -F ‘^A’ ‘{print $10}’ | sort | uniq -c
查找当前日志文件 500 错误的访问:
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’
查找当前日志文件 500 错误的数量:
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’ | wc -l
查找某一分钟内 500 错误访问的数量:
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’ | grep ’09:00’ | wc-l
查找耗时超过 1s 的慢请求:
tail -f access.log | awk -F ‘^A’ ‘{if($6》1) print $0}’
假如只想查看某些位:
tail -f access.log | awk -F ‘^A’ ‘{if($6》1) print $3″|”$4}’
查找 502 错误最多的 URL:
cat access.log | awk -F ‘^A’ ‘{if($5==502) print $11}’ | sort | uniq -c
查找 200 空白页
cat access.log | awk -F ‘^A’ ‘{if($5==200 && $8 《 100) print $3″|”$4″|”$11″|”$6}’
查看实时日志数据流
tail -f access.log | cat -e
或者
tail -f access.log | tr ‘^A’ ‘|’
sed -n '/04\/Dec\/2015:07:30:53/,/04\/Dec\/2015:08:30:55/'p access.log | more 查看一段时间的日志
sed -n '/08\/Dec\/2015:15:48:01/,/08\/Dec\/2015:15:55:59/p' access.log > new.log
更多Nginx相关技术文章,请访问Nginx教程栏目进行学习!
The above is the detailed content of How to view nginx logs. For more information, please follow other related articles on the PHP Chinese website!

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.

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

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.

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

The server does not have permission to access the requested resource, resulting in a nginx 403 error. Solutions include: Check file permissions. Check the .htaccess configuration. Check nginx configuration. Configure SELinux permissions. Check the firewall rules. Troubleshoot other causes such as browser problems, server failures, or other possible errors.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

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.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.