{"id":63843,"date":"2025-04-29T08:22:45","date_gmt":"2025-04-29T00:22:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63843\/"},"modified":"2025-04-29T08:22:45","modified_gmt":"2025-04-29T00:22:45","slug":"nginx%e5%a6%82%e4%bd%95%e5%bc%80%e5%90%af%e4%bc%aa%e9%9d%99%e6%80%81-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63843\/","title":{"rendered":"nginx\u5982\u4f55\u5f00\u542f\u4f2a\u9759\u6001"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5f00\u542f nginx \u4f2a\u9759\u6001\uff1f\u542f\u7528 multiviews \u6a21\u5757\uff0c\u5141\u8bb8\u670d\u52a1\u5668\u6839\u636e\u6269\u5c55\u540d\u641c\u7d22\u6587\u4ef6\u3002\u6dfb\u52a0\u4f2a\u9759\u6001\u89c4\u5219\uff0c\u5c06 .php url \u91cd\u5199\u5230\u5339\u914d\u7684 php \u6587\u4ef6\u3002\u786e\u4fdd web \u670d\u52a1\u5668\u8fdb\u7a0b\u6709\u6743\u8bbf\u95ee php \u6587\u4ef6\u3002\u91cd\u542f nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff0c\u4ece\u800c\u5b9e\u73b0 url \u6620\u5c04\u5230\u6587\u4ef6\u8def\u5f84\u7684\u529f\u80fd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/06\/2024060615302297987.jpg\" class=\"aligncenter\" title=\"nginx\u5982\u4f55\u5f00\u542f\u4f2a\u9759\u6001\u63d2\u56fe\" alt=\"nginx\u5982\u4f55\u5f00\u542f\u4f2a\u9759\u6001\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5f00\u542f Nginx \u4f2a\u9759\u6001<\/strong><\/p>\n<p>Nginx \u4f2a\u9759\u6001\u662f\u4e00\u79cd\u914d\u7f6e\u65b9\u6cd5\uff0c\u5141\u8bb8\u670d\u52a1\u5668\u5c06 URL \u6620\u5c04\u5230\u5185\u90e8\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\uff0c\u4ece\u800c\u5b9e\u73b0\u7c7b\u4f3c\u4e8e Apache .ht \u4e2d Rewrite \u6a21\u5757\u7684\u529f\u80fd\u3002\u5f00\u542f Nginx \u4f2a\u9759\u6001\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u542f\u7528 MultiViews<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528 MultiViews \u6a21\u5757\uff1a<\/p>\n<pre>server {\n    ...\n\n    location \/ {\n        autoindex on;\n        multiviews on;\n    }\n\n    ...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u914d\u7f6e\u4f2a\u9759\u6001\u89c4\u5219<\/strong><\/p>\n<p>\u5728\u76f8\u540c\u7684\u4f4d\u7f6e\u5757\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4f2a\u9759\u6001\u89c4\u5219\uff1a<\/p>\n<pre>location ~ .php$ {\n    try_files $uri =404;\n    fastcgi_pass   127.0.0.1:9000;\n    fastcgi_index  index.php;\n    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\n    include        fastcgi_params;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4fee\u6539\u6587\u4ef6\u6743\u9650<\/strong><\/p>\n<p>\u786e\u4fdd Web \u670d\u52a1\u5668\u8fdb\u7a0b\u6709\u6743\u8bbf\u95ee\u60a8\u7684 PHP \u6587\u4ef6\u3002\u4e3a\u6b64\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>sudo chmod 644 \/var\/www\/html\/*.php<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u91cd\u542f Nginx<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u91cd\u542f Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u539f\u7406\u8bf4\u660e\uff1a<\/strong><\/p>\n<p>\u901a\u8fc7\u542f\u7528 MultiViews \u6a21\u5757\uff0cNginx \u5141\u8bb8\u670d\u52a1\u5668\u6839\u636e\u8bf7\u6c42\u7684\u6587\u4ef6\u6269\u5c55\u540d\u641c\u7d22\u591a\u4e2a\u6587\u4ef6\u3002\u4f2a\u9759\u6001\u89c4\u5219\u5c06\u6240\u6709\u4ee5 .php \u7ed3\u5c3e\u7684 URL \u91cd\u5199\u5230\u4e0e\u4e4b\u5339\u914d\u7684 PHP \u6587\u4ef6\u3002\u5f53\u8bf7\u6c42\u5904\u7406\u65f6\uff0cNginx \u5c06 PHP \u6587\u4ef6\u4f20\u9012\u7ed9 FastCGI \u5904\u7406\u7a0b\u5e8f\uff0cFastCGI \u5904\u7406\u7a0b\u5e8f\u7136\u540e\u6267\u884c PHP \u4ee3\u7801\u5e76\u751f\u6210\u54cd\u5e94\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5f00\u542f\u4f2a\u9759\u6001\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>\u5982\u4f55\u5f00\u542f nginx \u4f2a\u9759\u6001\uff1f\u542f\u7528 multiviews \u6a21\u5757\uff0c\u5141\u8bb8\u670d\u52a1\u5668\u6839\u636e\u6269\u5c55\u540d\u641c\u7d22\u6587\u4ef6\u3002\u6dfb\u52a0\u4f2a\u9759\u6001\u89c4\u5219\uff0c\u5c06 .php url \u91cd\u5199\u5230\u5339\u914d\u7684 php \u6587\u4ef6\u3002\u786e\u4fdd web \u670d\u52a1\u5668\u8fdb\u7a0b\u6709\u6743\u8bbf\u95ee php \u6587\u4ef6\u3002\u91cd\u542f nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff0c\u4ece\u800c\u5b9e\u73b0 url \u6620\u5c04\u5230\u6587\u4ef6\u8def\u5f84\u7684\u529f\u80fd\u3002 \u5982\u4f55\u5f00\u542f Nginx \u4f2a\u9759\u6001 Nginx \u4f2a\u9759\u6001\u662f\u4e00\u79cd\u914d\u7f6e\u65b9\u6cd5\uff0c\u5141\u8bb8\u670d\u52a1\u5668\u5c06 URL \u6620\u5c04\u5230\u5185\u90e8\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\uff0c\u4ece\u800c\u5b9e\u73b0\u7c7b\u4f3c\u4e8e Apache .ht \u4e2d Rewrite \u6a21\u5757\u7684\u529f\u80fd\u3002\u5f00\u542f Nginx \u4f2a\u9759\u6001\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u542f\u7528 MultiViews \u9996\u5148\uff0c\u5728 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528 MultiViews \u6a21\u5757\uff1a server { &#8230; location \/ { autoindex on; multiviews on; } &#8230; } \u767b\u5f55\u540e\u590d\u5236 2. [&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-63843","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63843","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=63843"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63843\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}