{"id":63580,"date":"2025-04-29T10:59:09","date_gmt":"2025-04-29T02:59:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63580\/"},"modified":"2025-04-29T10:59:09","modified_gmt":"2025-04-29T02:59:09","slug":"nginx%e7%9a%84%e6%97%a5%e5%bf%97%e6%80%8e%e4%b9%88%e5%88%87%e5%89%b2-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63580\/","title":{"rendered":"nginx\u7684\u65e5\u5fd7\u600e\u4e48\u5207\u5272"},"content":{"rendered":"<blockquote><p>\n  \u95ee\u9898\uff1a\u5982\u4f55\u5728 nginx \u4e2d\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\uff1f\u6b65\u9aa4\uff1a\u5728 nginx \u914d\u7f6e\u4e2d\u542f\u7528\u65e5\u5fd7\u5207\u5272\uff0c\u6307\u5b9a\u65e5\u5fd7\u8def\u5f84\u548c\u683c\u5f0f\u3002\u521b\u5efa\u65e5\u5fd7\u5b58\u50a8\u76ee\u5f55\u3002\u8bbe\u7f6e cron \u4f5c\u4e1a\u5b9a\u671f\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\u3002\u9a8c\u8bc1\u65e5\u5fd7\u5207\u5272\u662f\u5426\u6309\u9884\u671f\u5de5\u4f5c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052721453828108.jpg\" class=\"aligncenter\" title=\"nginx\u7684\u65e5\u5fd7\u600e\u4e48\u5207\u5272\u63d2\u56fe\" alt=\"nginx\u7684\u65e5\u5fd7\u600e\u4e48\u5207\u5272\u63d2\u56fe\" \/><\/p>\n<p><strong>Nginx \u65e5\u5fd7\u5207\u5272<\/strong><\/p>\n<p>Nginx \u65e5\u5fd7\u5207\u5272\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8fc7\u7a0b\uff0c\u53ef\u5e2e\u52a9\u7ba1\u7406\u548c\u7ef4\u62a4\u7f51\u7ad9\u65e5\u5fd7\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u5728 Nginx \u4e2d\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528\u65e5\u5fd7\u5207\u5272<\/strong><\/p>\n<p>\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u901a\u5e38\u4f4d\u4e8e \/etc\/\/nginx.conf\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<pre>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\naccess_log  \/var\/log\/nginx\/access.log  main;\n\naccess_log \/var\/log\/nginx\/access.log.1  main  daily rotate=4;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> _log \u6307\u4ee4\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\u548c\u683c\u5f0f\u3002<\/li>\n<li>rotate=4 \u53c2\u6570\u6307\u5b9a\u8981\u4fdd\u7559 4 \u4e2a\u65cb\u8f6c\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>2. \u521b\u5efa\u65e5\u5fd7\u76ee\u5f55<\/strong><\/p>\n<p>\u786e\u4fdd\u5df2\u521b\u5efa\u7528\u4e8e\u5b58\u50a8\u65e5\u5fd7\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6b64\u76ee\u5f55\u662f \/var\/log\/nginx\u3002<\/p>\n<p><strong>3. \u8bbe\u7f6e\u65e5\u5fd7\u5207\u5272 cron \u4f5c\u4e1a<\/strong><\/p>\n<p>\u521b\u5efa cron \u4f5c\u4e1a\u4ee5\u5b9a\u671f\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>0 0 * * * \/usr\/sbin\/logrotate \/etc\/logrotate.d\/nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u4f5c\u4e1a\u5c06\u6bcf\u5929\u51cc\u6668 0 \u70b9\u8fd0\u884c\u65e5\u5fd7\u5207\u5272\u811a\u672c\u3002<\/p>\n<p><strong>4. \u9a8c\u8bc1\u65e5\u5fd7\u5207\u5272<\/strong><\/p>\n<p>\u91cd\u65b0\u52a0\u8f7d Nginx \u914d\u7f6e\u5e76\u68c0\u67e5\u65e5\u5fd7\u5207\u5272\u662f\u5426\u6b63\u5728\u6309\u9884\u671f\u5de5\u4f5c\uff1a<\/p>\n<pre>nginx -s reload\n\ntail -n 4 \/var\/log\/nginx\/access.log\ntail -n 4 \/var\/log\/nginx\/access.log.1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u60a8\u5e94\u8be5\u80fd\u770b\u5230\u65e5\u5fd7\u6587\u4ef6\u5df2\u6309\u65f6\u95f4\u5207\u5272\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7684\u65e5\u5fd7\u600e\u4e48\u5207\u5272\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\uff1a\u5982\u4f55\u5728 nginx \u4e2d\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\uff1f\u6b65\u9aa4\uff1a\u5728 nginx \u914d\u7f6e\u4e2d\u542f\u7528\u65e5\u5fd7\u5207\u5272\uff0c\u6307\u5b9a\u65e5\u5fd7\u8def\u5f84\u548c\u683c\u5f0f\u3002\u521b\u5efa\u65e5\u5fd7\u5b58\u50a8\u76ee\u5f55\u3002\u8bbe\u7f6e cron \u4f5c\u4e1a\u5b9a\u671f\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\u3002\u9a8c\u8bc1\u65e5\u5fd7\u5207\u5272\u662f\u5426\u6309\u9884\u671f\u5de5\u4f5c\u3002 Nginx \u65e5\u5fd7\u5207\u5272 Nginx \u65e5\u5fd7\u5207\u5272\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8fc7\u7a0b\uff0c\u53ef\u5e2e\u52a9\u7ba1\u7406\u548c\u7ef4\u62a4\u7f51\u7ad9\u65e5\u5fd7\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u5728 Nginx \u4e2d\u5207\u5272\u65e5\u5fd7\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a 1. \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528\u65e5\u5fd7\u5207\u5272 \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u901a\u5e38\u4f4d\u4e8e \/etc\/\/nginx.conf\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6307\u4ee4\uff1a log_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216; &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216; &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;; access_log \/var\/log\/nginx\/access.log main; access_log \/var\/log\/nginx\/access.log.1 main daily rotate=4; \u767b\u5f55\u540e\u590d\u5236 _log \u6307\u4ee4\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\u548c\u683c\u5f0f\u3002 rotate=4 \u53c2\u6570\u6307\u5b9a\u8981\u4fdd\u7559 4 \u4e2a\u65cb\u8f6c\u65e5\u5fd7\u6587\u4ef6\u3002 2. \u521b\u5efa\u65e5\u5fd7\u76ee\u5f55 \u786e\u4fdd\u5df2\u521b\u5efa\u7528\u4e8e\u5b58\u50a8\u65e5\u5fd7\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6b64\u76ee\u5f55\u662f \/var\/log\/nginx\u3002 3. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63580","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63580"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63580\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}