{"id":48310,"date":"2024-12-02T16:55:56","date_gmt":"2024-12-02T08:55:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48310\/"},"modified":"2024-12-02T16:55:56","modified_gmt":"2024-12-02T08:55:56","slug":"nginx-%e4%b8%ad-try_files-%e6%8c%87%e4%bb%a4%ef%bc%9a%e5%a6%82%e4%bd%95%e6%a0%b9%e6%8d%ae%e4%b8%8d%e5%90%8c%e7%9a%84%e6%83%85%e5%86%b5%e9%80%89%e6%8b%a9%e5%90%88%e9%80%82%e7%9a%84%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48310\/","title":{"rendered":"Nginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Nginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aNginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730012097671de3c14fcb5.jpg\" class=\"aligncenter\" title=\"Nginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f\u63d2\u56fe\" alt=\"Nginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Nginx \u4e2d try_files \u914d\u7f6e\u8be6\u89e3<\/strong><\/p>\n<p>\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0ctry_files \u6307\u4ee4\u7528\u4e8e\u51b3\u5b9a\u5f53\u8bf7\u6c42\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u91c7\u53d6\u4f55\u79cd\u63aa\u65bd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e94\u4e2a\u4e0d\u540c\u7684 try_files \u914d\u7f6e\u9009\u9879\uff0c\u5206\u6790\u5176\u7ec6\u5fae\u5dee\u522b\uff0c\u5e76\u89e3\u91ca Nginx \u4e2d\u51fa\u73b0\u7684\u53d8\u91cf\u3002<\/p>\n<p><strong>try_files \u9009\u9879\u89e3\u6790<\/strong><\/p>\n<ol>\n<li>\n<p><strong>try_files $uri $uri\/ \/index.php$args;<\/strong><\/p>\n<ul>\n<li>\u4ec5\u5f53 $uri \u5339\u914d\u771f\u5b9e\u6587\u4ef6\u65f6\uff0c\u624d\u4f1a\u91cd\u5b9a\u5411\u5230 index.php\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>try_files $uri $uri\/ \/index.php?\/$uri;<\/strong><\/p>\n<ul>\n<li>\u603b\u662f\u5c06\u8bf7\u6c42\u9644\u52a0\u5230 $uri \u5e76\u5728 index.php \u4e2d\u91cd\u5199\u67e5\u8be2\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>try_files $uri $uri\/ \/index.php?$query_string;<\/strong><\/p>\n<ul>\n<li>\u59cb\u7ec8\u91cd\u5199 index.php \u4e2d\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u5373\u4f7f $uri \u5b58\u5728\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>try_files $uri \/index.php?$args;<\/strong><\/p>\n<ul>\n<li>\u5982\u679c $uri \u5b58\u5728\uff0c\u5219\u5c06\u67e5\u8be2\u5b57\u7b26\u4e32\u9644\u52a0\u5230 index.php \u4e2d\u3002\u5426\u5219\uff0c\u4ec5\u91cd\u5b9a\u5411\u5230 index.php\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>try_files $uri \/index.php$is_args$args;<\/strong><\/p>\n<ul>\n<li>\u4e0e\u9009\u9879 4 \u7c7b\u4f3c\uff0c\u4f46\u5982\u679c $args \u4e3a\u7a7a\uff0c\u5219\u5b83\u4f1a\u9644\u52a0\u4e00\u4e2a\u95ee\u53f7\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u53d8\u91cf\u89e3\u6790<\/strong><\/p>\n<ul>\n<li><strong>$uri\uff1a<\/strong>\u8bf7\u6c42\u7684 URL \u8def\u5f84\u3002<\/li>\n<li><strong>$args\uff1a<\/strong>\u9644\u52a0\u5230\u67e5\u8be2\u5b57\u7b26\u4e32\u7684\u8bf7\u6c42\u53c2\u6570\uff08\u5982\u679c\u6709\uff09\u3002<\/li>\n<li><strong>$query_string\uff1a<\/strong>\u8bf7\u6c42\u4e2d\u7684\u4e00\u5bf9\u952e\u503c\u53c2\u6570\u3002<\/li>\n<li>**$is_args\uff1a**\u5982\u679c $args \u4e3a\u7a7a\uff0c\u5219\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff1b\u5426\u5219\u4e3a\u4e00\u4e2a\u95ee\u53f7\u3002<\/li>\n<\/ul>\n<p><strong>\u9009\u9879\u5bf9\u6bd4<\/strong><\/p>\n<ul>\n<li>\u9009\u9879 1 \u4ec5\u5728\u8bf7\u6c42\u7684\u6587\u4ef6\u5b58\u5728\u65f6\u91cd\u5b9a\u5411\u5230 index.php\u3002<\/li>\n<li>\u9009\u9879 2 \u548c 3 \u59cb\u7ec8\u91cd\u5199 index.php \u4e2d\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u9009\u9879 4 \u5728 $uri \u5b58\u5728\u65f6\u9644\u52a0\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u5426\u5219\u4ec5\u91cd\u5b9a\u5411\u5230 index.php\u3002<\/li>\n<li>\u9009\u9879 5 \u7c7b\u4f3c\u4e8e\u9009\u9879 4\uff0c\u4f46\u5982\u679c $args \u4e3a\u7a7a\uff0c\u5219\u5b83\u4f1a\u9644\u52a0\u4e00\u4e2a\u95ee\u53f7\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u5408\u9002\u7684 try_files \u9009\u9879\u81f3\u5173\u91cd\u8981\uff0c\u5b83\u53d6\u51b3\u4e8e\u5177\u4f53\u60c5\u51b5\u4e0b\u7684\u7ec6\u5fae\u8981\u6c42\u3002\u4e86\u89e3\u8fd9\u4e9b\u9009\u9879\u53ca\u5176\u7ec6\u5fae\u5dee\u522b\u5c06\u5e2e\u52a9\u60a8\u6839\u636e\u9700\u8981\u914d\u7f6e Nginx\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aNginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300aNginx \u4e2d try_files \u6307\u4ee4\uff1a\u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u914d\u7f6e\u9009\u9879\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ Nginx \u4e2d try_files \u914d\u7f6e\u8be6\u89e3 \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0ctry_files \u6307\u4ee4\u7528\u4e8e\u51b3\u5b9a\u5f53\u8bf7\u6c42\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u91c7\u53d6\u4f55\u79cd\u63aa\u65bd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e94\u4e2a\u4e0d\u540c\u7684 try_files \u914d\u7f6e\u9009\u9879\uff0c\u5206\u6790\u5176\u7ec6\u5fae\u5dee\u522b\uff0c\u5e76\u89e3\u91ca Nginx \u4e2d\u51fa\u73b0\u7684\u53d8\u91cf\u3002 try_files \u9009\u9879\u89e3\u6790 try_files $uri $uri\/ \/index.php$args; \u4ec5\u5f53 $uri \u5339\u914d\u771f\u5b9e\u6587\u4ef6\u65f6\uff0c\u624d\u4f1a\u91cd\u5b9a\u5411\u5230 index.php\u3002 try_files $uri $uri\/ \/index.php?\/$uri; \u603b\u662f\u5c06\u8bf7\u6c42\u9644\u52a0\u5230 $uri \u5e76\u5728 index.php \u4e2d\u91cd\u5199\u67e5\u8be2\u5b57\u7b26\u4e32\u3002 try_files $uri $uri\/ \/index.php?$query_string; \u59cb\u7ec8\u91cd\u5199 index.php \u4e2d\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u5373\u4f7f $uri \u5b58\u5728\u3002 try_files $uri \/index.php?$args; \u5982\u679c $uri \u5b58\u5728\uff0c\u5219\u5c06\u67e5\u8be2\u5b57\u7b26\u4e32\u9644\u52a0\u5230 index.php [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48310","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48310","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=48310"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48310\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}