{"id":18041,"date":"2024-11-18T16:22:57","date_gmt":"2024-11-18T08:22:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18041\/"},"modified":"2024-11-18T16:22:57","modified_gmt":"2024-11-18T08:22:57","slug":"nginx%e6%80%8e%e4%b9%88%e4%bc%aa%e9%9d%99%e6%80%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18041\/","title":{"rendered":"nginx\u600e\u4e48\u4f2a\u9759\u6001"},"content":{"rendered":"<p><strong> \u4f2a\u9759\u6001\u914d\u7f6e<\/strong><\/p>\n<p>\u4f2a\u9759\u6001\u662f\u6307\u5c06\u52a8\u6001\u7f51\u5740\u8f6c\u6362\u4e3a\u9759\u6001\u7f51\u5740\uff0c\u4ece\u800c\u63d0\u9ad8\u7f51\u7ad9\u5b89\u5168\u6027\u5e76\u6539\u5584\u7528\u6237\u4f53\u9a8c\u3002Nginx \u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u914d\u7f6e\u4f2a\u9759\u6001\uff1a<\/p>\n<p><strong>1. \u542f\u7528\u4f2a\u9759\u6001\u6a21\u5757<\/strong><\/p>\n<p>\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u627e\u5230 http{} \u5757\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>load_module rewrite_module modules\/mod_rewrite.so;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b9a\u4e49\u4f2a\u9759\u6001\u89c4\u5219<\/strong><\/p>\n<p>\u5728 http{} \u5757\u5185\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4f2a\u9759\u6001\u89c4\u5219\uff1a<\/p>\n<pre>rewrite ^\/(.+) \/index.php?q=$1 last;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u89c4\u5219\u5c06\u5c06\u6240\u6709\u52a8\u6001 URL\uff08\u4ee5 \/ \u5f00\u5934\uff09\u91cd\u5199\u4e3a\u9759\u6001 URL\uff08\/index.php\uff09\uff0c\u5e76\u5c06\u52a8\u6001\u90e8\u5206\u4f5c\u4e3a q \u53c2\u6570\u4f20\u9012\u3002<\/p>\n<p><strong>3. \u5904\u7406\u67e5\u8be2\u5b57\u7b26\u4e32<\/strong><\/p>\n<p>\u5728 index.php \u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5904\u7406\u67e5\u8be2\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre>&lt;?php\n$query = $_GET['q'];\n\/\/ \u5904\u7406\u52a8\u6001\u5185\u5bb9\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u52a8\u6001 URL \/articles\/10\uff0c\u91cd\u5199\u540e\u5c06\u53d8\u4e3a \/index.php?q=articles\/10\u3002index.php \u5c06\u63a5\u6536 q \u53c2\u6570\u4e3a articles\/10\uff0c\u5e76\u663e\u793a\u76f8\u5e94\u7684\u6587\u7ae0\u3002<\/p>\n<p><strong>\u597d\u5904<\/strong><\/p>\n<p>\u4f2a\u9759\u6001\u914d\u7f6e\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u597d\u5904\uff1a<\/p>\n<ul>\n<li> <strong>\u63d0\u9ad8\u5b89\u5168\u6027\uff1a<\/strong>\u9690\u85cf\u52a8\u6001\u7f51\u5740\uff0c\u964d\u4f4e\u88ab\u653b\u51fb\u7684\u98ce\u9669\u3002<\/li>\n<li> <strong>\u6539\u5584\u7528\u6237\u4f53\u9a8c\uff1a<\/strong>\u9759\u6001\u7f51\u5740\u66f4\u6613\u4e8e\u8bb0\u4f4f\u548c\u5206\u4eab\u3002<\/li>\n<li> <strong>\u63d0\u9ad8\uff08SEO\uff09\uff1a<\/strong>\u641c\u7d22\u5f15\u64ce\u503e\u5411\u4e8e\u9759\u6001\u7f51\u5740\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u4f2a\u9759\u6001\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f2a\u9759\u6001\u914d\u7f6e \u4f2a\u9759\u6001\u662f\u6307\u5c06\u52a8\u6001\u7f51\u5740\u8f6c\u6362\u4e3a\u9759\u6001\u7f51\u5740\uff0c\u4ece\u800c\u63d0\u9ad8\u7f51\u7ad9\u5b89\u5168\u6027\u5e76\u6539\u5584\u7528\u6237\u4f53\u9a8c\u3002Nginx \u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u914d\u7f6e\u4f2a\u9759\u6001\uff1a 1. \u542f\u7528\u4f2a\u9759\u6001\u6a21\u5757 \u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u627e\u5230 http{} \u5757\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a load_module rewrite_module modules\/mod_rewrite.so; \u767b\u5f55\u540e\u590d\u5236 2. \u5b9a\u4e49\u4f2a\u9759\u6001\u89c4\u5219 \u5728 http{} \u5757\u5185\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4f2a\u9759\u6001\u89c4\u5219\uff1a rewrite ^\/(.+) \/index.php?q=$1 last; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u89c4\u5219\u5c06\u5c06\u6240\u6709\u52a8\u6001 URL\uff08\u4ee5 \/ \u5f00\u5934\uff09\u91cd\u5199\u4e3a\u9759\u6001 URL\uff08\/index.php\uff09\uff0c\u5e76\u5c06\u52a8\u6001\u90e8\u5206\u4f5c\u4e3a q \u53c2\u6570\u4f20\u9012\u3002 3. \u5904\u7406\u67e5\u8be2\u5b57\u7b26\u4e32 \u5728 index.php \u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5904\u7406\u67e5\u8be2\u5b57\u7b26\u4e32\uff1a &lt;?php $query = $_GET[&#8216;q&#8217;]; \/\/ \u5904\u7406\u52a8\u6001\u5185\u5bb9 ?&gt; \u767b\u5f55\u540e\u590d\u5236 4. \u793a\u4f8b \u4f8b\u5982\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u52a8\u6001 URL \/articles\/10\uff0c\u91cd\u5199\u540e\u5c06\u53d8\u4e3a \/index.php?q=articles\/10\u3002index.php \u5c06\u63a5\u6536 q \u53c2\u6570\u4e3a articles\/10\uff0c\u5e76\u663e\u793a\u76f8\u5e94\u7684\u6587\u7ae0\u3002 \u597d\u5904 [&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-18041","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18041","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=18041"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18041\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}