{"id":63577,"date":"2025-04-29T13:07:03","date_gmt":"2025-04-29T05:07:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63577\/"},"modified":"2025-04-29T13:07:03","modified_gmt":"2025-04-29T05:07:03","slug":"nginx%e6%80%8e%e4%b9%88%e5%8a%a0%e8%bd%bd%e6%96%87%e4%bb%b6%e8%b7%af%e5%be%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63577\/","title":{"rendered":"nginx\u600e\u4e48\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84"},"content":{"rendered":"<blockquote><p>\n  \u5728 nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e location \u5757\u3002location \u5757\u7684\u8bed\u6cd5\u4e3a\uff1alocation \/\u6587\u4ef6\u8def\u5f84 { }\u3002\u4f7f\u7528 root \u6307\u4ee4\u6307\u5b9a\u6839\u76ee\u5f55\uff0c\u4f8b\u5982\uff1alocation \/ { root \/usr\/share\/nginx\/html; }\u3002\u4f7f\u7528 index \u6307\u4ee4\u6307\u5b9a\u7d22\u5f15\u6587\u4ef6\uff0c\u4f8b\u5982\uff1aindex index.html;\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052721361946652.jpg\" class=\"aligncenter\" title=\"nginx\u600e\u4e48\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\u63d2\u56fe\" alt=\"nginx\u600e\u4e48\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84<\/strong><\/p>\n<p>Nginx \u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u3001\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u5e7f\u6cdb\u7528\u4e8e\u4e3a\u7f51\u7ad9\u3001\u5e94\u7528\u7a0b\u5e8f\u548c API \u63d0\u4f9b\u670d\u52a1\u3002\u4e3a\u4e86\u52a0\u8f7d\u548c\u670d\u52a1\u6587\u4ef6\uff0cNginx \u3092\u4f7f\u7528location \u5757\uff0c\u5b83\u5141\u8bb8\u5728\u8bf7\u6c42\u7684\u7279\u5b9a\u8def\u5f84\u548c\u6587\u4ef6\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u5b9a\u4e49\u52a8\u4f5c\u3002<\/p>\n<p><strong>\u914d\u7f6e location \u5757<\/strong><\/p>\n<p>\u8981\u5728 Nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\uff0c\u9700\u8981\u4e3a\u8981\u52a0\u8f7d\u7684\u6587\u4ef6\u914d\u7f6e\u4e00\u4e2a location \u5757\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>location \/\u6587\u4ef6\u8def\u5f84 {\n    # \u52a0\u8f7d\u6240\u9700\u7684\u6587\u4ef6\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u52a0\u8f7d\u6839\u76ee\u5f55\u4e2d\u7684 &#8220;index.html&#8221; \u6587\u4ef6\uff0clocation \u5757\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre>location \/ {\n    root \/usr\/share\/nginx\/html;\n    index index.html;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 root \u6307\u4ee4<\/strong><\/p>\n<p>root \u6307\u4ee4\u6307\u5b9a Nginx \u67e5\u627e\u6587\u4ef6\u7684\u6839\u76ee\u5f55\u3002\u6b64\u5904\uff0c\/usr\/share\/\/html \u662f Nginx \u5b89\u88c5\u9ed8\u8ba4\u7684\u6839\u76ee\u5f55\u3002\u5982\u679c\u9700\u8981\u52a0\u8f7d\u5176\u4ed6\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u5c06\u5176\u66ff\u6362\u4e3a\u6240\u9700\u76ee\u5f55\u3002<\/p>\n<p><strong>\u4f7f\u7528 index \u6307\u4ee4<\/strong><\/p>\n<p>index \u6307\u4ee4\u6307\u5b9a Nginx \u5728\u5ba2\u6237\u673a\u8bf7\u6c42\u6839\u76ee\u5f55\u65f6\u52a0\u8f7d\u7684\u6587\u4ef6\u3002\u6b64\u5904\uff0c&#8221;index.html&#8221; \u662f\u9ed8\u8ba4\u7d22\u5f15\u6587\u4ef6\uff0c\u5f53\u8bbf\u95ee\u6839\u76ee\u5f55\u65f6\u52a0\u8f7d\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6dfb\u52a0\u5176\u4ed6\u7d22\u5f15\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u9017\u53f7\u5206\u9694\u3002<\/p>\n<p><strong>Additional Notes<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5177\u6709\u6587\u4ef6\u8bbf\u95ee\u6743\u9650\uff0c\u4ee5\u907f\u514d 403 Forbidden \u9519\u8bef\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 allow \u548c deny \u6307\u4ee4\u63a7\u5236\u5bf9\u6587\u4ef6\u7684\u8bbf\u95ee\u3002<\/li>\n<li>location \u5757\u53ef\u4ee5\u5d4c\u5957\uff0c\u4ee5\u521b\u5efa\u66f4\u7cbe\u7ec6\u7684\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\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>\u5728 nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e location \u5757\u3002location \u5757\u7684\u8bed\u6cd5\u4e3a\uff1alocation \/\u6587\u4ef6\u8def\u5f84 { }\u3002\u4f7f\u7528 root \u6307\u4ee4\u6307\u5b9a\u6839\u76ee\u5f55\uff0c\u4f8b\u5982\uff1alocation \/ { root \/usr\/share\/nginx\/html; }\u3002\u4f7f\u7528 index \u6307\u4ee4\u6307\u5b9a\u7d22\u5f15\u6587\u4ef6\uff0c\u4f8b\u5982\uff1aindex index.html;\u3002 \u5982\u4f55\u5728 Nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84 Nginx \u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u3001\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u5e7f\u6cdb\u7528\u4e8e\u4e3a\u7f51\u7ad9\u3001\u5e94\u7528\u7a0b\u5e8f\u548c API \u63d0\u4f9b\u670d\u52a1\u3002\u4e3a\u4e86\u52a0\u8f7d\u548c\u670d\u52a1\u6587\u4ef6\uff0cNginx \u3092\u4f7f\u7528location \u5757\uff0c\u5b83\u5141\u8bb8\u5728\u8bf7\u6c42\u7684\u7279\u5b9a\u8def\u5f84\u548c\u6587\u4ef6\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u5b9a\u4e49\u52a8\u4f5c\u3002 \u914d\u7f6e location \u5757 \u8981\u5728 Nginx \u4e2d\u52a0\u8f7d\u6587\u4ef6\u8def\u5f84\uff0c\u9700\u8981\u4e3a\u8981\u52a0\u8f7d\u7684\u6587\u4ef6\u914d\u7f6e\u4e00\u4e2a location \u5757\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a location \/\u6587\u4ef6\u8def\u5f84 { # \u52a0\u8f7d\u6240\u9700\u7684\u6587\u4ef6 } \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u52a0\u8f7d\u6839\u76ee\u5f55\u4e2d\u7684 &#8220;index.html&#8221; \u6587\u4ef6\uff0clocation \u5757\u7684\u914d\u7f6e\u5982\u4e0b\uff1a location \/ { root \/usr\/share\/nginx\/html; index [&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-63577","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63577","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=63577"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63577\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}