{"id":51812,"date":"2023-06-01T18:05:39","date_gmt":"2023-06-01T10:05:39","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=51812"},"modified":"2023-06-01T18:05:39","modified_gmt":"2023-06-01T10:05:39","slug":"nginx-log","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nginx-log.html","title":{"rendered":"\u4f60\u9020\u5417\uff0c\u5982\u4f55\u7eaf\u624b\u5de5\u73a9\u8f6c Nginx \u65e5\u5fd7\uff01"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nNginx \u65e5\u5fd7\u5bf9\u4e8e\u5927\u90e8\u5206\u4eba\u6765\u8bf4\u662f\u4e2a\u672a\u88ab\u53d1\u6398\u7684\u5b9d\u85cf\uff0c\u603b\u7ed3\u4e4b\u524d\u505a\u67d0\u65e5\u5fd7\u5206\u6790\u7cfb\u7edf\u7684\u7ecf\u9a8c\uff0c\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b Nginx \u65e5\u5fd7\u7684\u7eaf\u624b\u5de5\u5206\u6790\u65b9\u5f0f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

Nginx \u65e5\u5fd7\u5bf9\u4e8e\u5927\u90e8\u5206\u4eba\u6765\u8bf4\u662f\u4e2a\u672a\u88ab\u53d1\u6398\u7684\u5b9d\u85cf\uff0c\u603b\u7ed3\u4e4b\u524d\u505a\u67d0\u65e5\u5fd7\u5206\u6790\u7cfb\u7edf\u7684\u7ecf\u9a8c\uff0c\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b Nginx \u65e5\u5fd7\u7684\u7eaf\u624b\u5de5\u5206\u6790\u65b9\u5f0f\u3002<\/p>\n

Nginx \u65e5\u5fd7\u76f8\u5173\u914d\u7f6e\u6709 2 \u4e2a\u5730\u65b9\uff1aaccess_log \u548c log_format \u3002<\/p>\n

\u9ed8\u8ba4\u7684\u683c\u5f0f\uff1a<\/strong><\/span><\/div>\n
access_log \/data\/logs\/nginx-access.log;\r\n\r\nlog_format old '$remote_addr [$time_local] $status $request_time $body_bytes_sent '\r\n    '\"$request\" \"$http_referer\" \"$http_user_agent\"';<\/pre>\n

\u76f8\u4fe1\u5927\u90e8\u5206\u7528\u8fc7 Nginx \u7684\u4eba\u5bf9\u9ed8\u8ba4 Nginx \u65e5\u5fd7\u683c\u5f0f\u914d\u7f6e\u90fd\u5f88\u719f\u6089\uff0c\u5bf9\u65e5\u5fd7\u7684\u5185\u5bb9\u4e5f\u5f88\u719f\u6089\u3002\u4f46\u662f\u9ed8\u8ba4\u914d\u7f6e\u548c\u683c\u5f0f\u867d\u7136\u53ef\u8bfb\uff0c\u4f46\u662f\u96be\u4ee5\u8ba1\u7b97\u3002<\/p>\n

Nginx \u65e5\u5fd7\u5237\u76d8\u76f8\u5173\u7b56\u7565\u53ef\u914d\u7f6e\uff1a<\/strong><\/span><\/div>\n

\u6bd4\u5982\uff0c\u8bbe\u7f6e buffer\uff0cbuffer \u6ee1 32k \u624d\u5237\u76d8\uff1b\u5047\u5982 buffer \u4e0d\u6ee1 5s \u949f\u5f3a\u5236\u5237\u76d8\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n

access_log \/data\/logs\/nginx-access.log buffer=32k flush=5s;<\/pre>\n

\u8fd9\u51b3\u5b9a\u4e86\u662f\u5426\u5b9e\u65f6\u770b\u5230\u65e5\u5fd7\u4ee5\u53ca\u65e5\u5fd7\u5bf9\u78c1\u76d8 IO \u7684\u5f71\u54cd\u3002<\/p>\n

Nginx \u65e5\u5fd7\u80fd\u591f\u8bb0\u5f55\u7684\u53d8\u91cf\u8fd8\u6709\u5f88\u591a\u6ca1\u51fa\u73b0\u5728\u9ed8\u8ba4\u914d\u7f6e\u4e2d\uff1a<\/strong><\/span><\/div>\n

\u6bd4\u5982\uff1a<\/p>\n