{"id":50000,"date":"2024-10-08T09:13:14","date_gmt":"2024-10-08T01:13:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/50000\/"},"modified":"2024-10-08T09:13:14","modified_gmt":"2024-10-08T01:13:14","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8-log_not_found-%e6%b8%9b%e5%b0%91%e6%97%a5%e8%aa%8c%e5%99%aa%e9%9f%b3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/50000\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u4f7f\u7528 log_not_found \u6e1b\u5c11\u65e5\u8a8c\u566a\u97f3"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8-log_not_found-%e6%b8%9b%e5%b0%91%e6%97%a5%e8%aa%8c%e5%99%aa%e9%9f%b3-bhhFayijWf\">Nginx \u6280\u5de7\uff1a\u4f7f\u7528 log_not_found \u6e1b\u5c11\u65e5\u8a8c\u566a\u97f3<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5f0f\u4e2d\u3002\u96a8\u8457\u7db2\u7ad9\u6d41\u91cf\u7684\u589e\u52a0\uff0c\u4f3a\u670d\u5668\u65e5\u8a8c\u7684\u7ba1\u7406\u8b8a\u5f97\u6108\u52a0\u91cd\u8981\u3002\u65e5\u8a8c\u4e0d\u50c5\u7528\u65bc\u6545\u969c\u6392\u9664\uff0c\u9084\u80fd\u63d0\u4f9b\u6709\u95dc\u7db2\u7ad9\u6027\u80fd\u548c\u7528\u6236\u884c\u70ba\u7684\u5bf6\u8cb4\u6578\u64da\u3002\u7136\u800c\uff0c\u7576\u4f3a\u670d\u5668\u6536\u5230\u5927\u91cf\u7684 404 \u932f\u8aa4\u8acb\u6c42\u6642\uff0c\u65e5\u8a8c\u4e2d\u6703\u51fa\u73fe\u5927\u91cf\u7684\u566a\u97f3\uff0c\u9019\u4f7f\u5f97\u91cd\u8981\u4fe1\u606f\u96e3\u4ee5\u8fa8\u8b58\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0cNginx \u63d0\u4f9b\u4e86\u4e00\u500b\u540d\u70ba <code>log_not_found<\/code> \u7684\u6307\u4ee4\uff0c\u80fd\u5920\u6709\u6548\u6e1b\u5c11\u9019\u985e\u65e5\u8a8c\u566a\u97f3\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-log_not_found%ef%bc%9f-bhhFayijWf\">\u4ec0\u9ebc\u662f log_not_found\uff1f<\/h2>\n<p><code>log_not_found<\/code> \u662f Nginx \u7684\u4e00\u500b\u914d\u7f6e\u6307\u4ee4\uff0c\u4e3b\u8981\u7528\u65bc\u63a7\u5236 404 \u932f\u8aa4\u65e5\u8a8c\u7684\u8a18\u9304\u884c\u70ba\u3002\u7576\u4f3a\u670d\u5668\u7121\u6cd5\u627e\u5230\u8acb\u6c42\u7684\u8cc7\u6e90\u6642\uff0c\u901a\u5e38\u6703\u751f\u6210\u4e00\u689d 404 \u932f\u8aa4\u65e5\u8a8c\u3002\u9019\u4e9b\u65e5\u8a8c\u5728\u6d41\u91cf\u8f03\u5927\u7684\u7db2\u7ad9\u4e0a\u53ef\u80fd\u6703\u8fc5\u901f\u7d2f\u7a4d\uff0c\u5c0e\u81f4\u65e5\u8a8c\u6587\u4ef6\u8b8a\u5f97\u9f90\u5927\u4e14\u96e3\u4ee5\u7ba1\u7406\u3002\u4f7f\u7528 <code>log_not_found<\/code> \u6307\u4ee4\uff0c\u53ef\u4ee5\u9078\u64c7\u4e0d\u8a18\u9304\u9019\u4e9b 404 \u932f\u8aa4\uff0c\u5f9e\u800c\u6e1b\u5c11\u65e5\u8a8c\u7684\u566a\u97f3\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-log_not_found%ef%bc%9f-bhhFayijWf\">\u5982\u4f55\u4f7f\u7528 log_not_found\uff1f<\/h2>\n<p>\u8981\u4f7f\u7528 <code>log_not_found<\/code> \u6307\u4ee4\uff0c\u60a8\u9700\u8981\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u9032\u884c\u8a2d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n        log_not_found off;  # \u95dc\u9589 404 \u932f\u8aa4\u65e5\u8a8c\n    }\n}<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u7576\u8acb\u6c42\u7684\u8cc7\u6e90\u4e0d\u5b58\u5728\u6642\uff0cNginx \u5c07\u4e0d\u6703\u8a18\u9304 404 \u932f\u8aa4\u65e5\u8a8c\u3002\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u6e1b\u5c11\u65e5\u8a8c\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u4e26\u4f7f\u7ba1\u7406\u8b8a\u5f97\u66f4\u52a0\u7c21\u55ae\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-log_not_found-%e7%9a%84%e5%a5%bd%e8%99%95-bhhFayijWf\">\u4f7f\u7528 log_not_found \u7684\u597d\u8655<\/h2>\n<ul>\n<li><strong>\u6e1b\u5c11\u65e5\u8a8c\u566a\u97f3\uff1a<\/strong>\u901a\u904e\u95dc\u9589\u4e0d\u5fc5\u8981\u7684 404 \u932f\u8aa4\u65e5\u8a8c\uff0c\u60a8\u53ef\u4ee5\u5c08\u6ce8\u65bc\u66f4\u91cd\u8981\u7684\u65e5\u8a8c\u4fe1\u606f\uff0c\u4f8b\u5982\u4f3a\u670d\u5668\u6027\u80fd\u548c\u5b89\u5168\u4e8b\u4ef6\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u6e1b\u5c11\u65e5\u8a8c\u5beb\u5165\u7684\u983b\u7387\u53ef\u4ee5\u63d0\u9ad8\u4f3a\u670d\u5668\u7684\u6574\u9ad4\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\u3002<\/li>\n<li><strong>\u7c21\u5316\u65e5\u8a8c\u7ba1\u7406\uff1a<\/strong>\u8f03\u5c0f\u7684\u65e5\u8a8c\u6587\u4ef6\u66f4\u6613\u65bc\u7ba1\u7406\u548c\u5206\u6790\uff0c\u8b93\u60a8\u80fd\u5920\u66f4\u5feb\u5730\u627e\u5230\u6240\u9700\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-bhhFayijWf\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u96d6\u7136 <code>log_not_found<\/code> \u6307\u4ee4\u80fd\u5920\u6709\u6548\u6e1b\u5c11\u65e5\u8a8c\u566a\u97f3\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u60a8\u53ef\u80fd\u4ecd\u7136\u5e0c\u671b\u8a18\u9304\u7279\u5b9a\u7684 404 \u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u7576\u7db2\u7ad9\u6b63\u5728\u9032\u884c\u91cd\u5927\u8b8a\u66f4\u6216\u91cd\u69cb\u6642\uff0c\u8a18\u9304\u9019\u4e9b\u932f\u8aa4\u53ef\u4ee5\u5e6b\u52a9\u60a8\u8b58\u5225\u7528\u6236\u9047\u5230\u7684\u554f\u984c\u3002\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u60a8\u53ef\u4ee5\u9078\u64c7\u5728\u7279\u5b9a\u7684\u6642\u9593\u6bb5\u5167\u555f\u7528 <code>log_not_found<\/code>\uff0c\u7136\u5f8c\u518d\u5c07\u5176\u95dc\u9589\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-bhhFayijWf\">\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528 Nginx \u7684 <code>log_not_found<\/code> \u6307\u4ee4\u662f\u4e00\u7a2e\u6709\u6548\u7684\u65b9\u5f0f\u4f86\u6e1b\u5c11\u65e5\u8a8c\u4e2d\u7684\u566a\u97f3\uff0c\u5f9e\u800c\u63d0\u9ad8\u4f3a\u670d\u5668\u7684\u6027\u80fd\u548c\u65e5\u8a8c\u7ba1\u7406\u7684\u6548\u7387\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u5c08\u6ce8\u65bc\u66f4\u91cd\u8981\u7684\u65e5\u8a8c\u4fe1\u606f\uff0c\u4e26\u78ba\u4fdd\u4f3a\u670d\u5668\u904b\u884c\u7684\u7a69\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f\u7db2\u7ad9\u6258\u7ba1\u9084\u662f\u61c9\u7528\u7a0b\u5f0f\u90e8\u7f72\uff0c\u6211\u5011\u7684\u670d\u52d9\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 Nginx \u7684 log_not_found \u6307\u4ee4\u4f86\u6e1b\u5c11\u65e5\u8a8c\u566a\u97f3\uff0c\u63d0\u5347\u4f3a\u670d\u5668\u6548\u80fd\u8207\u7ba1\u7406\u6548\u7387\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-50000","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50000","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=50000"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50000\/revisions"}],"predecessor-version":[{"id":50001,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50000\/revisions\/50001"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=50000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=50000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=50000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}