{"id":1442,"date":"2022-06-08T16:00:03","date_gmt":"2022-06-08T08:00:03","guid":{"rendered":"https:\/\/www.yeetrack.com\/?p=1442"},"modified":"2022-06-08T16:00:03","modified_gmt":"2022-06-08T08:00:03","slug":"nginx%e6%97%a5%e5%bf%97%e6%8c%89%e5%a4%a9%e5%88%87%e5%89%b2%ef%bc%8cif-time_iso8601-d4-d2-d2%e6%9c%aa%e7%94%9f%e6%95%88","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=1442","title":{"rendered":"nginx\u65e5\u5fd7\u6309\u5929\u5207\u5272\uff0cif ($time_iso8601 ~ &#8220;^(\\d{4})-(\\d{2})-(\\d{2})&#8221;)\u672a\u751f\u6548"},"content":{"rendered":"<p>\u5728\u4f7f\u7528Nginx\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u9632\u6b62\u5355\u4e2a\u65e5\u5fd7\u8fc7\u5927\uff0c\u90fd\u8981\u5bf9\u65e5\u5fd7\u8fdb\u884c\u5207\u5272\uff0c\u4e00\u822c\u662f\u6309\u7167\u5929\u3001\u5c0f\u65f6\u6216\u8005\u66f4\u7ec6\u7c92\u5ea6\u8fdb\u884c\u5207\u5272\uff0c\u914d\u7f6e\u65b9\u5f0f\u5982\u4e0b\uff1a  <\/p>\n<pre><code>    server {\n        # \u5176\u4ed6\u6307\u4ee4\n        if ($time_iso8601 ~ \"^(\\d{4})-(\\d{2})-(\\d{2})\") {\n            set $year $1;\n            set $month $2;\n            set $day $3;\n     }\n\n        access_log \/home\/$yourdir\/log\/access-$year-$month-$day.log;\n    }<\/code><\/pre>\n<p>\u4e4b\u524d\u6211\u662f\u5982\u4e0a\u914d\u7f6e\u7684\uff0c\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u5bf9\u4e8e\u7edd\u5927\u90e8\u5206\u8bf7\u6c42\u90fd\u6ca1\u95ee\u9898\uff0c\u4f46\u662f\u5728\u6e05\u7406\u65e5\u5fd7\u7684\u65f6\u5019\u53d1\u73b0\uff0c\u5c11\u91cf\u8bf7\u6c42\u6ca1\u6709\u6309\u5929\u6253\u5370\uff0c\u800c\u662f\u8f93\u51fa\u5728<strong>access-.log<\/strong>\u4e2d\uff0c\u5f88\u660e\u663e\u662f<code>$year<\/code>,<code>$month<\/code>,<code>$day<\/code>\u4e09\u4e2a\u53d8\u91cf\u6ca1\u6709\u8d4b\u503c\u3002\u89c2\u5bdf\u8fd9\u4e9b\u5c11\u91cf\u8bf7\u6c42\uff0c\u53d1\u73b0\u90fd\u662fhttp status=400\uff0c\u731c\u6d4b\u662f\u56e0\u4e3a\u5728\u5904\u7406400\u8bf7\u6c42\u65f6\uff0c\u67d0\u4e9b\u6307\u4ee4\u5f71\u54cd\u4e86if\u6307\u4ee4\u7684\u6267\u884c\uff0c\u5bfc\u81f4\u4e0a\u8ff0\u6307\u4ee4\u6ca1\u6709\u6267\u884c\u3002\u67e5\u9605nginx\u8d44\u6599\uff0c\u5b98\u65b9\u63a8\u8350\u4f7f\u7528map\u6307\u4ee4\uff0c\u66ff\u6362\u4e4b\u540e\uff0c\u53d1\u73b0\u53ef\u4ee5\u517c\u5bb9http status=400\u7684\u60c5\u51b5\uff0c\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre><code>    http {\n        include       mime.types;\n        default_type  application\/octet-stream;\n\n        log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n                  '$status $body_bytes_sent \"$http_referer\" '\n                  '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n        map $time_iso8601 $logdate {\n             '~^(?<ymd>\\d{4}-\\d{2}-\\d{2})' $ymd;\n            default    'date-not-found';\n        }\n\n        access_log  \/var\/log\/nginx\/yeetrack.access-$logdate.log  main;\n      ...\n    }<\/ymd><\/code><\/pre>\n<p>\u914d\u7f6e\u4e4b\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d<code>.\/nginx -s reload<\/code>\uff0c\u6ce8\u610fmap\u6307\u4ee4\u8981\u914d\u7f6e\u5728http\u914d\u7f6e\u5757\u4e2d\u3002<br \/>\n\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u6d4b\u8bd5\uff1a<\/p>\n<pre><code>    printf foo | nc yeetrack.com 80\n    printf foo | nc yeetrack.com 443<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528Nginx\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u9632\u6b62\u5355\u4e2a\u65e5\u5fd7\u8fc7\u5927\uff0c\u90fd\u8981\u5bf9\u65e5\u5fd7\u8fdb\u884c\u5207\u5272\uff0c\u4e00\u822c\u662f\u6309\u7167\u5929\u3001\u5c0f\u65f6\u6216\u8005\u66f4\u7ec6\u7c92\u5ea6\u8fdb\u884c\u5207\u5272\uff0c\u914d\u7f6e\u65b9\u5f0f\u5982\u4e0b\uff1a server { # \u5176\u4ed6\u6307\u4ee4 if ($time_iso8601 ~ &#8220;^(&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[34],"tags":[11,58],"class_list":["post-1442","post","type-post","status-publish","format-standard","hentry","category-software","tag-linux","tag-nginx"],"views":1585,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1442"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1442\/revisions"}],"predecessor-version":[{"id":1443,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1442\/revisions\/1443"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}