{"id":62138,"date":"2025-04-29T09:15:24","date_gmt":"2025-04-29T01:15:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62138\/"},"modified":"2025-04-29T09:15:24","modified_gmt":"2025-04-29T01:15:24","slug":"nginx-%e6%9c%80%e5%b0%8f%e9%85%8d%e7%bd%ae-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62138\/","title":{"rendered":"Nginx &#8211; \u6700\u5c0f\u914d\u7f6e"},"content":{"rendered":"<p> <br \/>\n<img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/4be89c7be17a32b0770b7a991d7dbcd1-0.png\" class=\"aligncenter\" title=\"Nginx &#8211; \u6700\u5c0f\u914d\u7f6e\u63d2\u56fe\" alt=\"Nginx &#8211; \u6700\u5c0f\u914d\u7f6e\u63d2\u56fe\" \/> <\/p>\n<p style=\"max-width:90%\">\u5b89\u5168\u670d\u52a1\u5668\u662f\u53ea\u5141\u8bb8\u6240\u9700\u6570\u91cf\u7684\u670d\u52a1\u5668\u3002\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u5355\u72ec\u542f\u7528\u5176\u4ed6\u529f\u80fd\u6765\u57fa\u4e8e\u6700\u5c0f\u7cfb\u7edf\u6784\u5efa\u670d\u52a1\u5668\u3002\u8fdb\u884c\u6700\u5c11\u7684\u914d\u7f6e\u4e5f\u6709\u52a9\u4e8e\u8c03\u8bd5\u3002\u5982\u679c\u8be5\u9519\u8bef\u5728\u6700\u5c0f\u7cfb\u7edf\u4e2d\u4e0d\u53ef\u7528\uff0c\u5219\u5206\u522b\u6dfb\u52a0\u529f\u80fd\uff0c\u7136\u540e\u7ee7\u7eed\u641c\u7d22\u9519\u8bef\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u8fd9\u662f\u8fd0\u884c\u6240\u9700\u7684\u6700\u4f4e\u914d\u7f6e:<\/p>\n<pre>#&nbsp;\/etc\/nginx\/nginx.confevents&nbsp;{}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;event&nbsp;context&nbsp;have&nbsp;to&nbsp;be&nbsp;defined&nbsp;to&nbsp;consider&nbsp;config&nbsp;validhttp&nbsp;{&nbsp;server&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;&nbsp;&nbsp;server_name&nbsp;&nbsp;javatpoint.co&nbsp;&nbsp;www.javatpoint.co&nbsp;&nbsp;*.javatpoint.co;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;\"Hello\";&nbsp;&nbsp;}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>Root,Location\u548ctry_files\u6307\u4ee4<\/h3>\n<h4>Root \u6307\u4ee4<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">root\u6307\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u8bf7\u6c42\u7684\u6839\u76ee\u5f55\uff0c\u4ece\u800c\u5141\u8bb8nginx\u5c06\u4f20\u5165\u7684\u8bf7\u6c42\u6620\u5c04\u5230\u6587\u4ef6\u7cfb\u7edf\u4e0a\u3002<\/p>\n<pre>server&nbsp;{&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;server_name&nbsp;javatpoint.co;&nbsp;&nbsp;root&nbsp;\/var\/www\/javatpoint.co;}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u5b83\u5141\u8bb8nginx\u6839\u636e\u8bf7\u6c42\u8fd4\u56de\u670d\u52a1\u5668\u5185\u5bb9:<\/p>\n<pre>javatpoint.co:80\/index.html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;\/var\/www\/learnfk.com\/index.htmljavatpoint.co:80\/foo\/index.html&nbsp;#&nbsp;returns&nbsp;\/var\/www\/learnfk.com\/foo\/index.html<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4>Location\u6307\u4ee4<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">location\u6307\u4ee4\u7528\u4e8e\u6839\u636e\u8bf7\u6c42\u7684URI(\u7edf\u4e00\u8d44\u6e90\u6807\u8bc6\u7b26)\u6765\u8bbe\u7f6e\u914d\u7f6e\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u8bed\u6cd5\u4e3a:<\/p>\n<pre>location&nbsp;[modifier]&nbsp;path<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u793a\u4f8b:<\/p>\n<pre>location&nbsp;\/foo&nbsp;{&nbsp;&nbsp;#&nbsp;...}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u5982\u679c\u672a\u6307\u5b9a\u4fee\u9970\u7b26\uff0c\u5219\u5c06\u8def\u5f84\u89c6\u4e3a\u524d\u7f00\uff0c\u4e4b\u540e\u53ef\u4ee5\u8ddf\u968f\u4efb\u4f55\u5185\u5bb9\u3002\u4e0a\u9762\u7684\u793a\u4f8b\u5c06\u5339\u914d:<\/p>\n<pre>\/foo\/fooo\/foo123\/foo\/bar\/index.html...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u6211\u4eec\u8fd8\u53ef\u4ee5\u5728\u7ed9\u5b9a\u7684\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u591a\u4e2alocation\u6307\u4ee4:<\/p>\n<pre>server&nbsp;{&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;server_name&nbsp;javatpoint.co;&nbsp;&nbsp;root&nbsp;\/var\/www\/javatpoint.co;&nbsp;&nbsp;location\/{&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;\"root\";&nbsp;&nbsp;}&nbsp;&nbsp;location&nbsp;\/foo&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;\"foo\";&nbsp;&nbsp;}}javatpoint.co:80&nbsp;&nbsp;\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;\"root\"javatpoint.co:80&nbsp;&nbsp;&nbsp;\/foo&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;\"foo\"javatpoint.co:80&nbsp;&nbsp;&nbsp;\/foo123&nbsp;#&nbsp;=&amp;gt;&nbsp;\"foo\"javatpoint.co:80&nbsp;&nbsp;&nbsp;\/bar&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;\"root\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">Nginx\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u53ef\u4ee5\u4e0e location \u6307\u4ee4\u7ed3\u5408\u4f7f\u7528\u7684\u4fee\u9970\u7b26\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u641c\u7d22\u516c\u4f17\u53f7Linux\u4e2d\u6587\u793e\u533a\u540e\u53f0\u56de\u590d\u201c\u79c1\u623f\u83dc\u201d\uff0c\u83b7\u53d6\u4e00\u4efd\u60ca\u559c\u793c\u5305\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u4fee\u9970\u7b26\u5df2\u5206\u914d\u4f18\u5148\u7ea7:<\/p>\n<pre>=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Exact&nbsp;match^~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Preferential&nbsp;match~&nbsp;&amp;amp;&amp;amp;&nbsp;~*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Regex&nbsp;matchno&nbsp;modifier&nbsp;-&nbsp;Prefix&nbsp;match<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u9996\u5148\uff0cnginx\u5c06\u68c0\u67e5\u6240\u6709\u7cbe\u786e\u5339\u914d\u9879\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5b83\u5c06\u5bfb\u627e\u4f18\u5148\u9009\u9879\u3002\u5982\u679c\u6b64\u5339\u914d\u4e5f\u5931\u8d25\uff0c\u5219\u5c06\u6309\u5176\u51fa\u73b0\u987a\u5e8f\u6d4b\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u3002\u5982\u679c\u5176\u4ed6\u6240\u6709\u64cd\u4f5c\u5747\u5931\u8d25\uff0c\u5219\u5c06\u4f7f\u7528\u6700\u540e\u4e00\u4e2a\u524d\u7f00\u5339\u914d\u3002<\/p>\n<pre>location&nbsp;\/match&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;'Prefix&nbsp;match:&nbsp;will&nbsp;match&nbsp;everything&nbsp;that&nbsp;starting&nbsp;with&nbsp;\/match';}location&nbsp;~*&nbsp;\/match[0-9]&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;'Case&nbsp;insensitive&nbsp;regex&nbsp;match';}location&nbsp;~&nbsp;\/MATCH[0-9]&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;'Case&nbsp;sensitive&nbsp;regex&nbsp;match';}location&nbsp;^~&nbsp;\/match0&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;'Preferential&nbsp;match';}location&nbsp;=&nbsp;\/match&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;'Exact&nbsp;match';}\/match&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;'Exact&nbsp;match'\/match0&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;'Preferential&nbsp;match'\/match1&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;'Case&nbsp;insensitive&nbsp;regex&nbsp;match'\/MATCH1&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;'Case&nbsp;sensitive&nbsp;regex&nbsp;match'\/match-abc&nbsp;#&nbsp;=&amp;gt;&nbsp;'Prefix&nbsp;match:&nbsp;matches&nbsp;everything&nbsp;that&nbsp;starting&nbsp;with&nbsp;\/match'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4>try_files\u6307\u4ee4<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u8be5\u6307\u4ee4\u5c1d\u8bd5\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u627e\u5230\u7684\u4efb\u4f55\u8def\u5f84\u3002<\/p>\n<pre>try_files&nbsp;$uri&nbsp;index.html&nbsp;=404;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u56e0\u6b64\uff0c\/foo.html\u5c06\u5c1d\u8bd5\u6309\u4ee5\u4e0b\u987a\u5e8f\u8fd4\u56de\u6587\u4ef6:<\/p>\n<pre>$uri(\/foo.html);index.html<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u5982\u679c\u672a\u627e\u5230:404<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u5982\u679c\u6211\u4eec\u5728\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u5b9a\u4e49try_files\uff0c\u7136\u540e\u5b9a\u4e49\u67e5\u627e\u6240\u6709\u8bf7\u6c42\u7684\u4f4d\u7f6e\uff0c\u5219\u4e0d\u4f1a\u6267\u884ctry_files\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u7684try_files\u5b9a\u4e49\u4e86\u5176\u4f2a\u4f4d\u7f6e\uff0c\u8be5\u4f2a\u4f4d\u7f6e\u662f\u53ef\u80fd\u7684\u6700\u4f4e\u7279\u5b9a\u4f4d\u7f6e\u3002\u56e0\u6b64\uff0c\u5b9a\u4e49location\/ \u4f1a\u6bd4\u6211\u4eec\u7684\u4f2a\u4f4d\u7f6e\u66f4\u5177\u4f53\u3002<\/p>\n<pre>server&nbsp;{&nbsp;&nbsp;try_files&nbsp;$uri&nbsp;\/index.html&nbsp;=404;&nbsp;&nbsp;location\/{&nbsp;&nbsp;}}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 15px;line-height: 2\">\u56e0\u6b64\uff0c\u6211\u4eec\u5e94\u8be5\u907f\u514d\u5728\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528try_files:<\/p>\n<pre>server&nbsp;{&nbsp;&nbsp;location\/{&nbsp;&nbsp;&nbsp;&nbsp;try_files&nbsp;$uri&nbsp;\/index.html&nbsp;=404;&nbsp;&nbsp;}}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNginx &#8211; \u6700\u5c0f\u914d\u7f6e\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>\u5b89\u5168\u670d\u52a1\u5668\u662f\u53ea\u5141\u8bb8\u6240\u9700\u6570\u91cf\u7684\u670d\u52a1\u5668\u3002\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u5355\u72ec\u542f\u7528\u5176\u4ed6\u529f\u80fd\u6765\u57fa\u4e8e\u6700\u5c0f\u7cfb\u7edf\u6784\u5efa\u670d\u52a1\u5668\u3002\u8fdb\u884c\u6700\u5c11\u7684\u914d\u7f6e\u4e5f\u6709\u52a9\u4e8e\u8c03\u8bd5\u3002\u5982\u679c\u8be5\u9519\u8bef\u5728\u6700\u5c0f\u7cfb\u7edf\u4e2d\u4e0d\u53ef\u7528\uff0c\u5219\u5206\u522b\u6dfb\u52a0\u529f\u80fd\uff0c\u7136\u540e\u7ee7\u7eed\u641c\u7d22\u9519\u8bef\u3002 \u8fd9\u662f\u8fd0\u884c\u6240\u9700\u7684\u6700\u4f4e\u914d\u7f6e: #&nbsp;\/etc\/nginx\/nginx.confevents&nbsp;{}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;event&nbsp;context&nbsp;have&nbsp;to&nbsp;be&nbsp;defined&nbsp;to&nbsp;consider&nbsp;config&nbsp;validhttp&nbsp;{&nbsp;server&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;&nbsp;&nbsp;server_name&nbsp;&nbsp;javatpoint.co&nbsp;&nbsp;www.javatpoint.co&nbsp;&nbsp;*.javatpoint.co;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;&#8220;Hello&#8221;;&nbsp;&nbsp;} \u767b\u5f55\u540e\u590d\u5236 Root,Location\u548ctry_files\u6307\u4ee4 Root \u6307\u4ee4 root\u6307\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u8bf7\u6c42\u7684\u6839\u76ee\u5f55\uff0c\u4ece\u800c\u5141\u8bb8nginx\u5c06\u4f20\u5165\u7684\u8bf7\u6c42\u6620\u5c04\u5230\u6587\u4ef6\u7cfb\u7edf\u4e0a\u3002 server&nbsp;{&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;server_name&nbsp;javatpoint.co;&nbsp;&nbsp;root&nbsp;\/var\/www\/javatpoint.co;} \u767b\u5f55\u540e\u590d\u5236 \u5b83\u5141\u8bb8nginx\u6839\u636e\u8bf7\u6c42\u8fd4\u56de\u670d\u52a1\u5668\u5185\u5bb9: javatpoint.co:80\/index.html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;\/var\/www\/learnfk.com\/index.htmljavatpoint.co:80\/foo\/index.html&nbsp;#&nbsp;returns&nbsp;\/var\/www\/learnfk.com\/foo\/index.html \u767b\u5f55\u540e\u590d\u5236 Location\u6307\u4ee4 location\u6307\u4ee4\u7528\u4e8e\u6839\u636e\u8bf7\u6c42\u7684URI(\u7edf\u4e00\u8d44\u6e90\u6807\u8bc6\u7b26)\u6765\u8bbe\u7f6e\u914d\u7f6e\u3002 \u8bed\u6cd5\u4e3a: location&nbsp;[modifier]&nbsp;path \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b: location&nbsp;\/foo&nbsp;{&nbsp;&nbsp;#&nbsp;&#8230;} \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u672a\u6307\u5b9a\u4fee\u9970\u7b26\uff0c\u5219\u5c06\u8def\u5f84\u89c6\u4e3a\u524d\u7f00\uff0c\u4e4b\u540e\u53ef\u4ee5\u8ddf\u968f\u4efb\u4f55\u5185\u5bb9\u3002\u4e0a\u9762\u7684\u793a\u4f8b\u5c06\u5339\u914d: \/foo\/fooo\/foo123\/foo\/bar\/index.html&#8230; \u767b\u5f55\u540e\u590d\u5236 \u6211\u4eec\u8fd8\u53ef\u4ee5\u5728\u7ed9\u5b9a\u7684\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u591a\u4e2alocation\u6307\u4ee4: server&nbsp;{&nbsp;&nbsp;listen&nbsp;80;&nbsp;&nbsp;server_name&nbsp;javatpoint.co;&nbsp;&nbsp;root&nbsp;\/var\/www\/javatpoint.co;&nbsp;&nbsp;location\/{&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;&#8220;root&#8221;;&nbsp;&nbsp;}&nbsp;&nbsp;location&nbsp;\/foo&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;200&nbsp;&#8220;foo&#8221;;&nbsp;&nbsp;}}javatpoint.co:80&nbsp;&nbsp;\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8220;root&#8221;javatpoint.co:80&nbsp;&nbsp;&nbsp;\/foo&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8220;foo&#8221;javatpoint.co:80&nbsp;&nbsp;&nbsp;\/foo123&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8220;foo&#8221;javatpoint.co:80&nbsp;&nbsp;&nbsp;\/bar&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8220;root&#8221; \u767b\u5f55\u540e\u590d\u5236 Nginx\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u53ef\u4ee5\u4e0e location \u6307\u4ee4\u7ed3\u5408\u4f7f\u7528\u7684\u4fee\u9970\u7b26\u3002 \u641c\u7d22\u516c\u4f17\u53f7Linux\u4e2d\u6587\u793e\u533a\u540e\u53f0\u56de\u590d\u201c\u79c1\u623f\u83dc\u201d\uff0c\u83b7\u53d6\u4e00\u4efd\u60ca\u559c\u793c\u5305\u3002 \u4fee\u9970\u7b26\u5df2\u5206\u914d\u4f18\u5148\u7ea7: =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;Exact&nbsp;match^~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;Preferential&nbsp;match~&nbsp;&amp;amp;&amp;amp;&nbsp;~*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211;&nbsp;Regex&nbsp;matchno&nbsp;modifier&nbsp;&#8211;&nbsp;Prefix&nbsp;match \u767b\u5f55\u540e\u590d\u5236 \u9996\u5148\uff0cnginx\u5c06\u68c0\u67e5\u6240\u6709\u7cbe\u786e\u5339\u914d\u9879\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5b83\u5c06\u5bfb\u627e\u4f18\u5148\u9009\u9879\u3002\u5982\u679c\u6b64\u5339\u914d\u4e5f\u5931\u8d25\uff0c\u5219\u5c06\u6309\u5176\u51fa\u73b0\u987a\u5e8f\u6d4b\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u3002\u5982\u679c\u5176\u4ed6\u6240\u6709\u64cd\u4f5c\u5747\u5931\u8d25\uff0c\u5219\u5c06\u4f7f\u7528\u6700\u540e\u4e00\u4e2a\u524d\u7f00\u5339\u914d\u3002 location&nbsp;\/match&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;&#8216;Prefix&nbsp;match:&nbsp;will&nbsp;match&nbsp;everything&nbsp;that&nbsp;starting&nbsp;with&nbsp;\/match&#8217;;}location&nbsp;~*&nbsp;\/match[0-9]&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;&#8216;Case&nbsp;insensitive&nbsp;regex&nbsp;match&#8217;;}location&nbsp;~&nbsp;\/MATCH[0-9]&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;&#8216;Case&nbsp;sensitive&nbsp;regex&nbsp;match&#8217;;}location&nbsp;^~&nbsp;\/match0&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;&#8216;Preferential&nbsp;match&#8217;;}location&nbsp;=&nbsp;\/match&nbsp;{&nbsp;&nbsp;return&nbsp;200&nbsp;&#8216;Exact&nbsp;match&#8217;;}\/match&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8216;Exact&nbsp;match&#8217;\/match0&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8216;Preferential&nbsp;match&#8217;\/match1&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8216;Case&nbsp;insensitive&nbsp;regex&nbsp;match&#8217;\/MATCH1&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8216;Case&nbsp;sensitive&nbsp;regex&nbsp;match&#8217;\/match-abc&nbsp;#&nbsp;=&amp;gt;&nbsp;&#8216;Prefix&nbsp;match:&nbsp;matches&nbsp;everything&nbsp;that&nbsp;starting&nbsp;with&nbsp;\/match&#8217; \u767b\u5f55\u540e\u590d\u5236 try_files\u6307\u4ee4 \u8be5\u6307\u4ee4\u5c1d\u8bd5\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u627e\u5230\u7684\u4efb\u4f55\u8def\u5f84\u3002 try_files&nbsp;$uri&nbsp;index.html&nbsp;=404; \u767b\u5f55\u540e\u590d\u5236 \u56e0\u6b64\uff0c\/foo.html\u5c06\u5c1d\u8bd5\u6309\u4ee5\u4e0b\u987a\u5e8f\u8fd4\u56de\u6587\u4ef6: $uri(\/foo.html);index.html \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u672a\u627e\u5230:404 \u5982\u679c\u6211\u4eec\u5728\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u5b9a\u4e49try_files\uff0c\u7136\u540e\u5b9a\u4e49\u67e5\u627e\u6240\u6709\u8bf7\u6c42\u7684\u4f4d\u7f6e\uff0c\u5219\u4e0d\u4f1a\u6267\u884ctry_files\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u7684try_files\u5b9a\u4e49\u4e86\u5176\u4f2a\u4f4d\u7f6e\uff0c\u8be5\u4f2a\u4f4d\u7f6e\u662f\u53ef\u80fd\u7684\u6700\u4f4e\u7279\u5b9a\u4f4d\u7f6e\u3002\u56e0\u6b64\uff0c\u5b9a\u4e49location\/ \u4f1a\u6bd4\u6211\u4eec\u7684\u4f2a\u4f4d\u7f6e\u66f4\u5177\u4f53\u3002 server&nbsp;{&nbsp;&nbsp;try_files&nbsp;$uri&nbsp;\/index.html&nbsp;=404;&nbsp;&nbsp;location\/{&nbsp;&nbsp;}} \u767b\u5f55\u540e\u590d\u5236 \u56e0\u6b64\uff0c\u6211\u4eec\u5e94\u8be5\u907f\u514d\u5728\u670d\u52a1\u5668\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528try_files: server&nbsp;{&nbsp;&nbsp;location\/{&nbsp;&nbsp;&nbsp;&nbsp;try_files&nbsp;$uri&nbsp;\/index.html&nbsp;=404;&nbsp;&nbsp;}} \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fNginx &#8211; \u6700\u5c0f\u914d\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-62138","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62138","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=62138"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62138\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}