{"id":61337,"date":"2025-04-29T08:52:48","date_gmt":"2025-04-29T00:52:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/61337\/"},"modified":"2025-04-29T08:52:48","modified_gmt":"2025-04-29T00:52:48","slug":"nginx%e9%94%99%e8%af%af%e9%a1%b5%e9%9d%a2%e9%85%8d%e7%bd%ae%ef%bc%8c%e4%bc%98%e9%9b%85%e5%a4%84%e7%90%86%e7%bd%91%e7%ab%99%e6%95%85%e9%9a%9c-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/61337\/","title":{"rendered":"Nginx\u9519\u8bef\u9875\u9762\u914d\u7f6e\uff0c\u4f18\u96c5\u5904\u7406\u7f51\u7ad9\u6545\u969c"},"content":{"rendered":"<p>nginx\u9519\u8bef\u9875\u9762\u914d\u7f6e\uff0c\u4f18\u96c5\u5904\u7406\u7f51\u7ad9\u6545\u969c<\/p>\n<p>\u5728\u73b0\u4ee3\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u4e00\u4e2a\u9ad8\u5ea6\u7a33\u5b9a\u548c\u53ef\u9760\u7684\u7f51\u7ad9\u662f\u4efb\u4f55\u4f01\u4e1a\u6216\u4e2a\u4eba\u8ffd\u6c42\u7684\u76ee\u6807\u3002\u7136\u800c\uff0c\u7531\u4e8e\u5404\u79cd\u539f\u56e0\uff0c\u7f51\u7ad9\u53ef\u80fd\u4f1a\u7ecf\u5386\u6545\u969c\u6216\u9519\u8bef\uff0c\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u7f51\u7edc\u95ee\u9898\u3001\u670d\u52a1\u5668\u95ee\u9898\u6216\u5e94\u7528\u7a0b\u5e8f\u9519\u8bef\u7b49\u3002<\/p>\n<p>\u4e3a\u4e86\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u548c\u4f18\u96c5\u5730\u5904\u7406\u4efb\u4f55\u53ef\u80fd\u53d1\u751f\u7684\u9519\u8bef\uff0cNginx\u4f5c\u4e3a\u4e00\u4e2a\u5f3a\u5927\u7684Web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u4e0d\u4ec5\u80fd\u591f\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u670d\u52a1\uff0c\u8fd8\u80fd\u591f\u7075\u6d3b\u5730\u914d\u7f6e\u9519\u8bef\u9875\u9762\u3002<\/p>\n<p>\u5728Nginx\u4e2d\uff0c\u9519\u8bef\u9875\u9762\u914d\u7f6e\u975e\u5e38\u7b80\u5355\u3002\u901a\u8fc7\u7f16\u8f91Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u9875\u9762\uff0c\u5e76\u5c06\u5176\u4e0e\u5bf9\u5e94\u7684\u9519\u8bef\u4ee3\u7801\u5173\u8054\u8d77\u6765\u3002<\/p>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u662f\/etc\/nginx\/nginx.conf\u6216\/etc\/nginx\/conf.d\/default.conf\uff0c\u5177\u4f53\u6587\u4ef6\u8def\u5f84\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u6839\u636e\u60a8\u7684\u5b89\u88c5\u65b9\u5f0f\u800c\u5b9a\u3002<\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u627e\u5230http\u6bb5\uff0c\u7136\u540e\u5728\u8be5\u6bb5\u5185\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>http {\n    # ...\n\n    error_page 404 \/404.html;\n    error_page 500 502 503 504 \/50x.html;\n\n    location = \/40x.html {\n        root \/usr\/share\/nginx\/html;\n    }\n\n    location = \/50x.html {\n        root \/usr\/share\/nginx\/html;\n    }\n\n    # ...\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u9519\u8bef\u9875\u9762\uff1a404\u9875\u9762\u548c50x\u9875\u9762\u3002404\u9875\u9762\u662f\u5f53\u8bbf\u95ee\u7684\u8d44\u6e90\u4e0d\u5b58\u5728\u65f6\u663e\u793a\u7684\u9875\u9762\uff0c50x\u9875\u9762\u662f\u5f53\u670d\u52a1\u5668\u8fd4\u56de500\u3001502\u3001503\u6216504\u9519\u8bef\u65f6\u663e\u793a\u7684\u9875\u9762\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u8fd9\u4e9b\u9519\u8bef\u9875\u9762\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNginx\u9519\u8bef\u9875\u9762\u5e94\u8be5\u4f4d\u4e8e\/usr\/share\/nginx\/html\/\u76ee\u5f55\u4e0b\u3002\u5728\u8be5\u76ee\u5f55\u4e0b\u521b\u5efa\u4e24\u4e2aHTML\u6587\u4ef6404.html\u548c50x.html\u5e76\u586b\u5199\u81ea\u5b9a\u4e49\u7684\u5185\u5bb9\u3002<\/p>\n<p>404.html\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>\n\n\n    &lt;title&gt;404 - Not Found&lt;\/title&gt;&lt;h1&gt;404 - Not Found&lt;\/h1&gt;\n    &lt;p&gt;\u5bf9\u4e0d\u8d77\uff0c\u4f60\u8bbf\u95ee\u7684\u9875\u9762\u4e0d\u5b58\u5728\u3002&lt;\/p&gt;\n\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>50x.html\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>\n\n\n    &lt;title&gt;50x - Server Error&lt;\/title&gt;&lt;h1&gt;50x - Server Error&lt;\/h1&gt;\n    &lt;p&gt;\u5bf9\u4e0d\u8d77\uff0c\u670d\u52a1\u5668\u51fa\u73b0\u95ee\u9898\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5\u3002&lt;\/p&gt;\n\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4fdd\u5b58\u5e76\u5173\u95ed\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u91cd\u65b0\u52a0\u8f7dNginx\u914d\u7f6e\uff1a<\/p>\n<pre>sudo service nginx reload<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u73b0\u5728\uff0c\u5728\u60a8\u7684\u7f51\u7ad9\u4e0a\u5982\u679c\u51fa\u73b0404\u9519\u8bef\u9875\u9762\u6216\u670d\u52a1\u5668\u9519\u8bef\u9875\u9762\uff0cNginx\u4f1a\u81ea\u52a8\u663e\u793a\u60a8\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u9875\u9762\uff0c\u800c\u4e0d\u662f\u9ed8\u8ba4\u7684Nginx\u9519\u8bef\u9875\u9762\u3002<\/p>\n<p>\u9664\u4e86\u8bbe\u7f6e\u9759\u6001HTML\u9875\u9762\u4f5c\u4e3a\u9519\u8bef\u9875\u9762\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u52a8\u6001\u811a\u672c\u8bed\u8a00\u751f\u6210\u9519\u8bef\u9875\u9762\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528PHP\u3001Python\u6216\u4efb\u4f55\u5176\u4ed6\u652f\u6301\u7684\u8bed\u8a00\u6765\u751f\u6210\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>error_page 404 \/404.php;\nerror_page 500 502 503 504 \/50x.php;\n\nlocation = \/40x.php {\n    root \/usr\/share\/nginx\/html;\n    fastcgi_pass 127.0.0.1:9000;\n    include fastcgi_params;\n}\n\nlocation = \/50x.php {\n    root \/usr\/share\/nginx\/html;\n    fastcgi_pass 127.0.0.1:9000;\n    include fastcgi_params;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8bf7\u786e\u4fdd\u60a8\u7684\u670d\u52a1\u5668\u4e0a\u5df2\u5b89\u88c5\u5e76\u914d\u7f6e\u4e86\u76f8\u5e94\u7684\u811a\u672c\u8bed\u8a00\u89e3\u91ca\u5668\u548cFastCGI\u670d\u52a1\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u751f\u6210\u66f4\u5177\u6709\u4ea4\u4e92\u6027\u548c\u4e2a\u6027\u5316\u7684\u9519\u8bef\u9875\u9762\uff0c\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>\u603b\u800c\u8a00\u4e4b\uff0c\u914d\u7f6eNginx\u7684\u9519\u8bef\u9875\u9762\u662f\u4e00\u9879\u7b80\u5355\u800c\u5f3a\u5927\u7684\u6280\u5de7\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4f18\u96c5\u5730\u5904\u7406\u7f51\u7ad9\u6545\u969c\u3002\u65e0\u8bba\u662f404\u9875\u9762\u8fd8\u662f\u670d\u52a1\u5668\u9519\u8bef\u9875\u9762\uff0c\u901a\u8fc7\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\uff0c\u5e76\u5411\u7528\u6237\u4f20\u8fbe\u6709\u7528\u7684\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5229\u7528\u811a\u672c\u8bed\u8a00\u6765\u751f\u6210\u52a8\u6001\u7684\u9519\u8bef\u9875\u9762\uff0c\u4ee5\u6ee1\u8db3\u66f4\u9ad8\u7ea7\u7684\u9700\u6c42\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u7406\u89e3\u548c\u914d\u7f6eNginx\u9519\u8bef\u9875\u9762\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNginx\u9519\u8bef\u9875\u9762\u914d\u7f6e\uff0c\u4f18\u96c5\u5904\u7406\u7f51\u7ad9\u6545\u969c\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>nginx\u9519\u8bef\u9875\u9762\u914d\u7f6e\uff0c\u4f18\u96c5\u5904\u7406\u7f51\u7ad9\u6545\u969c \u5728\u73b0\u4ee3\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u4e00\u4e2a\u9ad8\u5ea6\u7a33\u5b9a\u548c\u53ef\u9760\u7684\u7f51\u7ad9\u662f\u4efb\u4f55\u4f01\u4e1a\u6216\u4e2a\u4eba\u8ffd\u6c42\u7684\u76ee\u6807\u3002\u7136\u800c\uff0c\u7531\u4e8e\u5404\u79cd\u539f\u56e0\uff0c\u7f51\u7ad9\u53ef\u80fd\u4f1a\u7ecf\u5386\u6545\u969c\u6216\u9519\u8bef\uff0c\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u7f51\u7edc\u95ee\u9898\u3001\u670d\u52a1\u5668\u95ee\u9898\u6216\u5e94\u7528\u7a0b\u5e8f\u9519\u8bef\u7b49\u3002 \u4e3a\u4e86\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u548c\u4f18\u96c5\u5730\u5904\u7406\u4efb\u4f55\u53ef\u80fd\u53d1\u751f\u7684\u9519\u8bef\uff0cNginx\u4f5c\u4e3a\u4e00\u4e2a\u5f3a\u5927\u7684Web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u4e0d\u4ec5\u80fd\u591f\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u670d\u52a1\uff0c\u8fd8\u80fd\u591f\u7075\u6d3b\u5730\u914d\u7f6e\u9519\u8bef\u9875\u9762\u3002 \u5728Nginx\u4e2d\uff0c\u9519\u8bef\u9875\u9762\u914d\u7f6e\u975e\u5e38\u7b80\u5355\u3002\u901a\u8fc7\u7f16\u8f91Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u9875\u9762\uff0c\u5e76\u5c06\u5176\u4e0e\u5bf9\u5e94\u7684\u9519\u8bef\u4ee3\u7801\u5173\u8054\u8d77\u6765\u3002 \u9996\u5148\uff0c\u60a8\u9700\u8981\u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u662f\/etc\/nginx\/nginx.conf\u6216\/etc\/nginx\/conf.d\/default.conf\uff0c\u5177\u4f53\u6587\u4ef6\u8def\u5f84\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u6839\u636e\u60a8\u7684\u5b89\u88c5\u65b9\u5f0f\u800c\u5b9a\u3002 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u627e\u5230http\u6bb5\uff0c\u7136\u540e\u5728\u8be5\u6bb5\u5185\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a http { # &#8230; error_page 404 \/404.html; error_page 500 502 503 504 \/50x.html; location = \/40x.html { root \/usr\/share\/nginx\/html; } location = \/50x.html { root \/usr\/share\/nginx\/html; } # &#8230; } \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u9519\u8bef\u9875\u9762\uff1a404\u9875\u9762\u548c50x\u9875\u9762\u3002404\u9875\u9762\u662f\u5f53\u8bbf\u95ee\u7684\u8d44\u6e90\u4e0d\u5b58\u5728\u65f6\u663e\u793a\u7684\u9875\u9762\uff0c50x\u9875\u9762\u662f\u5f53\u670d\u52a1\u5668\u8fd4\u56de500\u3001502\u3001503\u6216504\u9519\u8bef\u65f6\u663e\u793a\u7684\u9875\u9762\u3002 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u8fd9\u4e9b\u9519\u8bef\u9875\u9762\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNginx\u9519\u8bef\u9875\u9762\u5e94\u8be5\u4f4d\u4e8e\/usr\/share\/nginx\/html\/\u76ee\u5f55\u4e0b\u3002\u5728\u8be5\u76ee\u5f55\u4e0b\u521b\u5efa\u4e24\u4e2aHTML\u6587\u4ef6404.html\u548c50x.html\u5e76\u586b\u5199\u81ea\u5b9a\u4e49\u7684\u5185\u5bb9\u3002 404.html\u793a\u4f8b\u4ee3\u7801\uff1a &lt;title&gt;404 &#8211; Not Found&lt;\/title&gt;&lt;h1&gt;404 &#8211; Not Found&lt;\/h1&gt; &lt;p&gt;\u5bf9\u4e0d\u8d77\uff0c\u4f60\u8bbf\u95ee\u7684\u9875\u9762\u4e0d\u5b58\u5728\u3002&lt;\/p&gt; \u767b\u5f55\u540e\u590d\u5236 50x.html\u793a\u4f8b\u4ee3\u7801\uff1a &lt;title&gt;50x &#8211; Server Error&lt;\/title&gt;&lt;h1&gt;50x &#8211; [&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-61337","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61337","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=61337"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61337\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=61337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=61337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=61337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}