﻿{"id":1375,"date":"2015-11-03T11:23:15","date_gmt":"2015-11-03T03:23:15","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1375"},"modified":"2015-11-03T11:23:15","modified_gmt":"2015-11-03T03:23:15","slug":"nginx-log-%e8%ae%b0%e5%bd%95%e8%af%b7%e6%b1%82%e7%9a%84%e5%a4%b4%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/linux\/1375","title":{"rendered":"nginx log \u8bb0\u5f55\u8bf7\u6c42\u7684\u5934\u4fe1\u606f"},"content":{"rendered":"<p>\u8bb0\u5f55\u8bbf\u95ee\u7684log\uff0c\u4e3a\u4e86\u5728\u51fa\u73b0\u7279\u6b8a\u60c5\u51b5\u65f6\uff0c\u65b9\u4fbf\u68c0\u67e5\u51fa\u73b0\u95ee\u9898\u7684\u5730\u65b9\u3002<\/p>\n<p>log_format access &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;\n&#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;\n&#8216;&#8221;$http_user_agent&#8221; $http_x_forwarded_for&#8217;;\naccess_log \/var\/log\/51yip.log access;<\/p>\n<p>\u8bb0\u5f55\u4e0b\uff0c\u7528\u6237ip,\u7528\u6237\u771f\u5b9eip,\u7528\u6237\u8bbf\u95ee\u65f6\u95f4\uff0c\u7528\u6237\u8bbf\u95ee\u7684\u6e38\u89c8\u5668\u4fe1\u606f\u7b49\u3002\u8fd9\u91cc\u9762\u8fd9\u6837\u7684$remote_addr\u53d8\u91cf\u662f\u4ece\u54ea\u6765\u7684\u5462\uff1f<\/p>\n<p><strong>$arg_PARAMETER<\/strong> \u8fd9\u4e2a\u53d8\u91cf\u5305\u542b\u5728\u67e5\u8be2\u5b57\u7b26\u4e32\u65f6GET\u8bf7\u6c42PARAMETER\u7684\u503c\u3002\n<strong>$args <\/strong>\u8fd9\u4e2a\u53d8\u91cf\u7b49\u4e8e\u8bf7\u6c42\u884c\u4e2d\u7684\u53c2\u6570\u3002\n<strong>$binary_remote_addr<\/strong> \u4e8c\u8fdb\u5236\u7801\u5f62\u5f0f\u7684\u5ba2\u6237\u7aef\u5730\u5740\u3002\n<strong>$body_bytes_sent<\/strong>\n<strong>$content_length <\/strong>\u8bf7\u6c42\u5934\u4e2d\u7684Content-length\u5b57\u6bb5\u3002\n<strong>$content_type <\/strong>\u8bf7\u6c42\u5934\u4e2d\u7684Content-Type\u5b57\u6bb5\u3002\n<strong>$cookie_COOKIE <\/strong>cookie COOKIE\u7684\u503c\u3002\n<strong>$document_root <\/strong>\u5f53\u524d\u8bf7\u6c42\u5728root\u6307\u4ee4\u4e2d\u6307\u5b9a\u7684\u503c\u3002\n<strong>$document_uri <\/strong>\u4e0e$uri\u76f8\u540c\u3002\n<strong>$host <\/strong>\u8bf7\u6c42\u4e2d\u7684\u4e3b\u673a\u5934\u5b57\u6bb5\uff0c\u5982\u679c\u8bf7\u6c42\u4e2d\u7684\u4e3b\u673a\u5934\u4e0d\u53ef\u7528\uff0c\u5219\u4e3a\u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c42\u7684\u670d\u52a1\u5668\u540d\u79f0\u3002\n<strong>$is_args <\/strong>\u5982\u679c$args\u8bbe\u7f6e\uff0c\u503c\u4e3a&#8221;?&#8221;\uff0c\u5426\u5219\u4e3a&#8221;&#8221;\u3002\n<strong>$limit_rate<\/strong> \u8fd9\u4e2a\u53d8\u91cf\u53ef\u4ee5\u9650\u5236\u8fde\u63a5\u901f\u7387\u3002\n<strong>$nginx_version <\/strong>\u5f53\u524d\u8fd0\u884c\u7684nginx\u7248\u672c\u53f7\u3002\n<strong>$query_string <\/strong>\u4e0e$args\u76f8\u540c\u3002\n<strong>$remote_addr <\/strong>\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\u3002\n<strong>$remote_port <\/strong>\u5ba2\u6237\u7aef\u7684\u7aef\u53e3\u3002\n<strong>$remote_user <\/strong>\u5df2\u7ecf\u7ecf\u8fc7Auth Basic Module\u9a8c\u8bc1\u7684\u7528\u6237\u540d\u3002\n<strong>$request_filename<\/strong> \u5f53\u524d\u8fde\u63a5\u8bf7\u6c42\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u7531root\u6216alias\u6307\u4ee4\u4e0eURI\u8bf7\u6c42\u751f\u6210\u3002\n<strong>$request_body <\/strong>\u8fd9\u4e2a\u53d8\u91cf\uff080.7.58+\uff09\u5305\u542b\u8bf7\u6c42\u7684\u4e3b\u8981\u4fe1\u606f\u3002\u5728\u4f7f\u7528proxy_pass\u6216fastcgi_pass\u6307\u4ee4\u7684location\u4e2d\u6bd4\u8f83\u6709\u610f\u4e49\u3002\n<strong>$request_body_file<\/strong> \u5ba2\u6237\u7aef\u8bf7\u6c42\u4e3b\u4f53\u4fe1\u606f\u7684\u4e34\u65f6\u6587\u4ef6\u540d\u3002\n<strong>$request_completion <\/strong>\u8bf7\u6c42\u5b8c\u6210\n<strong>$request_method<\/strong> \u8fd9\u4e2a\u53d8\u91cf\u662f\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u52a8\u4f5c\uff0c\u901a\u5e38\u4e3aGET\u6216POST\u3002\u5305\u62ec0.8.20\u53ca\u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u8fd9\u4e2a\u53d8\u91cf\u603b\u4e3amain request\u4e2d\u7684\u52a8\u4f5c\uff0c\u5982\u679c\u5f53\u524d\u8bf7\u6c42\u662f\u4e00\u4e2a\u5b50\u8bf7\u6c42\uff0c\u5e76\u4e0d\u4f7f\u7528\u8fd9\u4e2a\u5f53\u524d\u8bf7\u6c42\u7684\u52a8\u4f5c\u3002\n<strong>$request_uri<\/strong> \u8fd9\u4e2a\u53d8\u91cf\u7b49\u4e8e\u5305\u542b\u4e00\u4e9b\u5ba2\u6237\u7aef\u8bf7\u6c42\u53c2\u6570\u7684\u539f\u59cbURI\uff0c\u5b83\u65e0\u6cd5\u4fee\u6539\uff0c\u8bf7\u67e5\u770b$uri\u66f4\u6539\u6216\u91cd\u5199URI\u3002\n<strong>$schemeHTTP <\/strong>\u65b9\u6cd5\uff08\u5982http\uff0chttps\uff09\u3002\u6309\u9700\u4f7f\u7528\uff0c\u4f8b\uff1a\nrewrite ^(.+)$ $scheme:\/\/example.com$1 redirect;<\/p>\n<p><strong>$server_addr <\/strong>\u670d\u52a1\u5668\u5730\u5740\uff0c\u5728\u5b8c\u6210\u4e00\u6b21\u7cfb\u7edf\u8c03\u7528\u540e\u53ef\u4ee5\u786e\u5b9a\u8fd9\u4e2a\u503c\uff0c\u5982\u679c\u8981\u7ed5\u5f00\u7cfb\u7edf\u8c03\u7528\uff0c\u5219\u5fc5\u987b\u5728listen\u4e2d\u6307\u5b9a\u5730\u5740\u5e76\u4e14\u4f7f\u7528bind\u53c2\u6570\u3002\n<strong>$server_name <\/strong>\u670d\u52a1\u5668\u540d\u79f0\u3002\n<strong>$server_port <\/strong>\u8bf7\u6c42\u5230\u8fbe\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7\u3002\n<strong>$server_protocol <\/strong>\u8bf7\u6c42\u4f7f\u7528\u7684\u534f\u8bae\uff0c\u901a\u5e38\u662fHTTP\/1.0\u6216HTTP\/1.1\u3002\n<strong>$uri <\/strong>\u8bf7\u6c42\u4e2d\u7684\u5f53\u524dURI(\u4e0d\u5e26\u8bf7\u6c42\u53c2\u6570\uff0c\u53c2\u6570\u4f4d\u4e8e$args)\uff0c\u53ef\u4ee5\u4e0d\u540c\u4e8e\u6d4f\u89c8\u5668\u4f20\u9012\u7684$request_uri\u7684\u503c\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u5185\u90e8\u91cd\u5b9a\u5411\uff0c\u6216\u8005\u4f7f\u7528index\u6307\u4ee4\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p><strong>\u4e0a\u9762\u7684\u8fd9\u4e9b\u662fnginx \u652f\u6301\u4e00\u4e9b\u5185\u7f6e\u7684\u53d8\u91cf\uff0c\u5f53\u7136\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff0c\u4f8b\u5982<\/strong><\/p>\n<p>$http_x_forwarded_for<\/p>\n<p>\u8fd9\u4e2a\u53d8\u91cf\u5c31\u662f\u81ea\u5b9a\u4e49\u7684\uff0c\u7528\u6765\u83b7\u5f97\u7528\u4e86\u4ee3\u7406\u7528\u6237\u7684\u771f\u5b9eIP\u3002<\/p>\n<p><strong>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>\u8bb0\u5f55\u8bbf\u95ee\u7684log\uff0c\u4e3a\u4e86\u5728\u51fa\u73b0\u7279\u6b8a\u60c5\u51b5\u65f6\uff0c\u65b9\u4fbf\u68c0\u67e5\u51fa\u73b0\u95ee\u9898\u7684\u5730\u65b9\u3002 log_format access &#8216;$remote_addr &#8211; $remote_user [$time_l&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[352,268,438],"class_list":["post-1375","post","type-post","status-publish","format-standard","hentry","category-linux","tag-log","tag-nginx","tag-var"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1375"}],"version-history":[{"count":1,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1375\/revisions"}],"predecessor-version":[{"id":1376,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1375\/revisions\/1376"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}