HTTP Status Codes
HTTP response status codes are three-digit numbers that indicate the outcome of a request. Common status codes include:
200: Success301: Permanent redirect302: Temporary redirect304: Browser cache (not modified)403: Forbidden (permission denied)404: Resource not found500: Internal server error (server code error)502: Bad gateway (upstream resource not found)504: Gateway timeout
Request and Response Headers
When a browser (client) acecsses a website, it sends request headers, and the server responds with its own headers. Below is an example breakdown:
// 1. Overview
Request URL: http://www.52wiki.cn/static/bootstrap/css/bootstrap.min.css
Request Method: GET
Status Code: 200 OK (from memory cache)
Remote Address: 61.184.215.226:80
// 2. Client Request Headers
Accept: text/html,application/xhtml+xml,...
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Host: www.52wiki.cn
If-Modified-Since: Tue, 04 Dec 2018 09:58:20 GMT
If-None-Match: "a49-56b5ce607fe00"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)...
"--- empty line ---"
"--- request body ---"
// 3. Server Response Headers
HTTP/1.1 304 Not Modified
Date: Fri, 14 Sep 2018 09:14:28 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
ETag: "a49-56b5ce607fe00"
"--- empty line ---"
"--- response body ---"
Nginx Log Statistics
Use the following command-line tools to analyze Nginx access logs (access.log):
-
Count unique IPs (UV):
awk '{print $1}' access.log | sort | uniq -c | wc -l -
Count total requests (PV):
awk '{print $7}' access.log | wc -l -
Find most requested URLs:
awk '{print $7}' access.log | sort | uniq -c | sort -n -k 1 -r | more -
Find most frequent IP addresses:
awk '{print $1}' access.log | sort | uniq -c | sort -n -k 1 -r | more