{"id":33498,"date":"2024-09-30T01:27:42","date_gmt":"2024-09-29T17:27:42","guid":{"rendered":"https:\/\/server.hk\/cnblog\/33498\/"},"modified":"2024-09-30T01:27:42","modified_gmt":"2024-09-29T17:27:42","slug":"apache%e6%8c%87%e4%bb%a4%ef%bc%9amod_log_config-%e6%97%a5%e8%aa%8c%e9%85%8d%e7%bd%ae%e6%a8%a1%e7%b5%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/33498\/","title":{"rendered":"Apache\u6307\u4ee4\uff1amod_log_config (\u65e5\u8a8c\u914d\u7f6e\u6a21\u7d44)"},"content":{"rendered":"<h1 id=\"apache%e6%8c%87%e4%bb%a4%ef%bc%9amod_log_config-%e6%97%a5%e8%aa%8c%e9%85%8d%e7%bd%ae%e6%a8%a1%e7%b5%84-XadrlbuARq\">Apache\u6307\u4ee4\uff1amod_log_config (\u65e5\u8a8c\u914d\u7f6e\u6a21\u7d44)<\/h1>\n<p>\u5728\u7db2\u7d61\u4f3a\u670d\u5668\u7684\u7ba1\u7406\u4e2d\uff0c\u65e5\u8a8c\u8a18\u9304\u662f\u4e00\u500b\u81f3\u95dc\u91cd\u8981\u7684\u529f\u80fd\u3002Apache HTTP Server\u4f5c\u70ba\u6700\u6d41\u884c\u7684\u7db2\u9801\u4f3a\u670d\u5668\u4e4b\u4e00\uff0c\u5176\u65e5\u8a8c\u914d\u7f6e\u6a21\u7d44mod_log_config\u63d0\u4f9b\u4e86\u9748\u6d3b\u4e14\u5f37\u5927\u7684\u65e5\u8a8c\u8a18\u9304\u529f\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0emod_log_config\u7684\u57fa\u672c\u6982\u5ff5\u3001\u914d\u7f6e\u65b9\u6cd5\u53ca\u5176\u61c9\u7528\u7bc4\u4f8b\u3002<\/p>\n<h2 id=\"mod_log_config%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-XadrlbuARq\">mod_log_config\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>mod_log_config\u662fApache\u7684\u4e00\u500b\u6a21\u7d44\uff0c\u5c08\u9580\u7528\u65bc\u914d\u7f6e\u4f3a\u670d\u5668\u7684\u65e5\u8a8c\u8a18\u9304\u3002\u5b83\u5141\u8a31\u7528\u6236\u81ea\u5b9a\u7fa9\u65e5\u8a8c\u683c\u5f0f\uff0c\u4e26\u8a18\u9304\u5404\u7a2e\u8acb\u6c42\u7684\u8a73\u7d30\u4fe1\u606f\u3002\u9019\u4e9b\u65e5\u8a8c\u5c0d\u65bc\u6545\u969c\u6392\u9664\u3001\u5b89\u5168\u5206\u6790\u548c\u6027\u80fd\u76e3\u63a7\u7b49\u65b9\u9762\u90fd\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e6%97%a5%e8%aa%8c%e6%a0%bc%e5%bc%8f-XadrlbuARq\">\u65e5\u8a8c\u683c\u5f0f<\/h2>\n<p>mod_log_config\u652f\u6301\u591a\u7a2e\u65e5\u8a8c\u683c\u5f0f\uff0c\u6700\u5e38\u898b\u7684\u683c\u5f0f\u662f\u201cCommon Log Format (CLF)\u201d\u548c\u201cCombined Log Format\u201d\u3002<\/p>\n<ul>\n<li><strong>Common Log Format (CLF)<\/strong>\uff1a\u9019\u662f\u4e00\u7a2e\u6a19\u6e96\u683c\u5f0f\uff0c\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a<br \/>\n        <code>host ident authuser date request status bytes<\/code>\n    <\/li>\n<li><strong>Combined Log Format<\/strong>\uff1a\u5728CLF\u7684\u57fa\u790e\u4e0a\uff0c\u589e\u52a0\u4e86\u7528\u6236\u4ee3\u7406\u548c\u5f15\u7528\u9801\u9762\u7684\u4fe1\u606f\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<br \/>\n        <code>host ident authuser date request status bytes referer user-agent<\/code>\n    <\/li>\n<\/ul>\n<h2 id=\"%e9%85%8d%e7%bd%aemod_log_config-XadrlbuARq\">\u914d\u7f6emod_log_config<\/h2>\n<p>\u8981\u555f\u7528mod_log_config\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fddApache\u4f3a\u670d\u5668\u5df2\u7d93\u5b89\u88dd\u4e26\u555f\u7528\u8a72\u6a21\u7d44\u3002\u63a5\u4e0b\u4f86\uff0c\u53ef\u4ee5\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u662fhttpd.conf\u6216apache2.conf\uff09\u4e2d\u9032\u884c\u65e5\u8a8c\u914d\u7f6e\u3002<\/p>\n<h3 id=\"%e5%9f%ba%e6%9c%ac%e9%85%8d%e7%bd%ae%e7%a4%ba%e4%be%8b-XadrlbuARq\">\u57fa\u672c\u914d\u7f6e\u793a\u4f8b<\/h3>\n<pre><code>\n# \u555f\u7528\u8a2a\u554f\u65e5\u8a8c\nCustomLog logs\/access.log combined\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u6307\u4ee4\u5c07\u8a2a\u554f\u65e5\u8a8c\u8a18\u9304\u5230logs\/access.log\u6587\u4ef6\u4e2d\uff0c\u4e26\u4f7f\u7528\u201cCombined Log Format\u201d\u3002<\/p>\n<h3 id=\"%e8%87%aa%e5%ae%9a%e7%be%a9%e6%97%a5%e8%aa%8c%e6%a0%bc%e5%bc%8f-XadrlbuARq\">\u81ea\u5b9a\u7fa9\u65e5\u8a8c\u683c\u5f0f<\/h3>\n<p>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u65e5\u8a8c\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u81ea\u5b9a\u7fa9\u683c\u5f0f\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\n# \u81ea\u5b9a\u7fa9\u65e5\u8a8c\u683c\u5f0f\nLogFormat \"%h %l %u %t \"%r\" %&gt;s %b\" my_custom_format\nCustomLog logs\/custom_access.log my_custom_format\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u65e5\u8a8c\u683c\u5f0f\u88ab\u5b9a\u7fa9\u70ba\u201cmy_custom_format\u201d\uff0c\u4e26\u5c07\u5176\u8a18\u9304\u5230logs\/custom_access.log\u6587\u4ef6\u4e2d\u3002<\/p>\n<h2 id=\"%e6%97%a5%e8%aa%8c%e8%bc%aa%e6%9b%bf%e8%88%87%e7%ae%a1%e7%90%86-XadrlbuARq\">\u65e5\u8a8c\u8f2a\u66ff\u8207\u7ba1\u7406<\/h2>\n<p>\u96a8\u8457\u6642\u9593\u7684\u63a8\u79fb\uff0c\u65e5\u8a8c\u6587\u4ef6\u53ef\u80fd\u6703\u8b8a\u5f97\u975e\u5e38\u9f90\u5927\uff0c\u56e0\u6b64\u9700\u8981\u9032\u884c\u65e5\u8a8c\u8f2a\u66ff\u3002Apache\u901a\u5e38\u8207logrotate\u5de5\u5177\u4e00\u8d77\u4f7f\u7528\uff0c\u4ee5\u81ea\u52d5\u7ba1\u7406\u65e5\u8a8c\u6587\u4ef6\u7684\u5927\u5c0f\u548c\u6578\u91cf\u3002<\/p>\n<h3 id=\"logrotate%e9%85%8d%e7%bd%ae%e7%a4%ba%e4%be%8b-XadrlbuARq\">logrotate\u914d\u7f6e\u793a\u4f8b<\/h3>\n<pre><code>\n\/path\/to\/apache\/logs\/*.log {\n    daily\n    rotate 7\n    compress\n    missingok\n    notifempty\n}\n<\/code><\/pre>\n<p>\u9019\u6bb5\u914d\u7f6e\u5c07\u6bcf\u5929\u8f2a\u66ffApache\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u4fdd\u7559\u6700\u8fd17\u5929\u7684\u65e5\u8a8c\uff0c\u4e26\u5c0d\u820a\u65e5\u8a8c\u9032\u884c\u58d3\u7e2e\u3002<\/p>\n<h2 id=\"%e6%97%a5%e8%aa%8c%e5%88%86%e6%9e%90%e5%b7%a5%e5%85%b7-XadrlbuARq\">\u65e5\u8a8c\u5206\u6790\u5de5\u5177<\/h2>\n<p>\u70ba\u4e86\u66f4\u597d\u5730\u5229\u7528\u65e5\u8a8c\u6578\u64da\uff0c\u8a31\u591a\u7db2\u7ad9\u7ba1\u7406\u8005\u6703\u4f7f\u7528\u65e5\u8a8c\u5206\u6790\u5de5\u5177\uff0c\u5982AWStats\u6216GoAccess\uff0c\u9019\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u53ef\u8996\u5316\u65e5\u8a8c\u6578\u64da\uff0c\u5f9e\u800c\u7372\u5f97\u6709\u50f9\u503c\u7684\u898b\u89e3\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XadrlbuARq\">\u7e3d\u7d50<\/h2>\n<p>mod_log_config\u6a21\u7d44\u70baApache\u4f3a\u670d\u5668\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u65e5\u8a8c\u8a18\u9304\u529f\u80fd\uff0c\u901a\u904e\u81ea\u5b9a\u7fa9\u65e5\u8a8c\u683c\u5f0f\u548c\u6709\u6548\u7684\u65e5\u8a8c\u7ba1\u7406\uff0c\u7db2\u7ad9\u7ba1\u7406\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u76e3\u63a7\u548c\u5206\u6790\u7db2\u7ad9\u6d41\u91cf\u3002\u7121\u8ad6\u662f\u7528\u65bc\u6545\u969c\u6392\u9664\u9084\u662f\u5b89\u5168\u5206\u6790\uff0c\u6b63\u78ba\u914d\u7f6e\u65e5\u8a8c\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728\u9999\u6e2f\u4f7f\u7528<code><a href=\"https:\/\/server.hk\">VPS<\/a><\/code> \u9032\u884cApache\u4f3a\u670d\u5668\u7684\u8a2d\u7f6e\u548c\u7ba1\u7406\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Apache\u7684mod_log_config\u6a21\u7d44\uff0c\u914d\u7f6e\u65e5\u8a8c\u683c\u5f0f\u548c\u8f38\u51fa\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u76e3\u63a7\u80fd\u529b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-33498","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=33498"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33498\/revisions"}],"predecessor-version":[{"id":33499,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33498\/revisions\/33499"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=33498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=33498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=33498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}