{"id":51041,"date":"2024-10-08T15:38:18","date_gmt":"2024-10-08T07:38:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51041\/"},"modified":"2024-10-08T15:38:18","modified_gmt":"2024-10-08T07:38:18","slug":"%e3%80%8anginx-%e7%af%87-%e4%ba%8c%e3%80%8b-nginx-%e6%98%af%e5%a6%82%e4%bd%95%e8%99%95%e7%90%86%e4%b8%80%e5%80%8b-http-%e8%ab%8b%e6%b1%82%e7%9a%84%e5%91%a2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51041\/","title":{"rendered":"\u300aNginx \u7bc7 \u4e8c\u300b Nginx \u662f\u5982\u4f55\u8655\u7406\u4e00\u500b HTTP \u8acb\u6c42\u7684\u5462"},"content":{"rendered":"<h1 id=\"%e3%80%8anginx-%e7%af%87-%e4%ba%8c%e3%80%8b-nginx-%e6%98%af%e5%a6%82%e4%bd%95%e8%99%95%e7%90%86%e4%b8%80%e5%80%8b-http-%e8%ab%8b%e6%b1%82%e7%9a%84%e5%91%a2-nDtNFJLYxj\">\u300aNginx \u7bc7 \u4e8c\u300b Nginx \u662f\u5982\u4f55\u8655\u7406\u4e00\u500b HTTP \u8acb\u6c42\u7684\u5462<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u8655\u7406 HTTP \u8acb\u6c42\u3002\u4e86\u89e3 Nginx \u5982\u4f55\u8655\u7406\u9019\u4e9b\u8acb\u6c42\uff0c\u5c0d\u65bc\u7db2\u7ad9\u7ba1\u7406\u54e1\u548c\u958b\u767c\u8005\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Nginx \u8655\u7406 HTTP \u8acb\u6c42\u7684\u904e\u7a0b\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"nginx-%e7%9a%84%e8%ab%8b%e6%b1%82%e8%99%95%e7%90%86%e6%b5%81%e7%a8%8b-nDtNFJLYxj\">Nginx \u7684\u8acb\u6c42\u8655\u7406\u6d41\u7a0b<\/h2>\n<p>Nginx \u7684\u8acb\u6c42\u8655\u7406\u6d41\u7a0b\u53ef\u4ee5\u5206\u70ba\u5e7e\u500b\u4e3b\u8981\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li><strong>\u63a5\u6536\u8acb\u6c42\uff1a<\/strong>\u7576\u7528\u6236\u901a\u904e\u700f\u89bd\u5668\u767c\u9001 HTTP \u8acb\u6c42\u6642\uff0cNginx \u9996\u5148\u63a5\u6536\u9019\u500b\u8acb\u6c42\u3002\u9019\u500b\u904e\u7a0b\u6d89\u53ca\u5230\u7db2\u7d61\u5c64\u7684\u6578\u64da\u5305\u50b3\u8f38\uff0cNginx \u6703\u5728\u5176\u914d\u7f6e\u7684\u7aef\u53e3\uff08\u901a\u5e38\u662f 80 \u6216 443\uff09\u4e0a\u76e3\u807d\u8acb\u6c42\u3002<\/li>\n<li><strong>\u89e3\u6790\u8acb\u6c42\uff1a<\/strong>Nginx \u6703\u89e3\u6790\u8acb\u6c42\u7684\u5404\u500b\u90e8\u5206\uff0c\u5305\u62ec\u8acb\u6c42\u65b9\u6cd5\uff08\u5982 GET \u6216 POST\uff09\u3001\u8acb\u6c42\u8def\u5f91\u3001HTTP \u7248\u672c\u4ee5\u53ca\u8acb\u6c42\u982d\u3002\u9019\u4e9b\u4fe1\u606f\u5c07\u7528\u65bc\u5f8c\u7e8c\u7684\u8655\u7406\u3002<\/li>\n<li><strong>\u67e5\u627e\u914d\u7f6e\uff1a<\/strong>Nginx \u6839\u64da\u8acb\u6c42\u7684\u8def\u5f91\u548c\u65b9\u6cd5\u67e5\u627e\u76f8\u61c9\u7684\u914d\u7f6e\u3002\u9019\u4e9b\u914d\u7f6e\u901a\u5e38\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b9a\u7fa9\uff0c\u4e26\u6c7a\u5b9a\u4e86\u5982\u4f55\u8655\u7406\u8acb\u6c42\u3002<\/li>\n<li><strong>\u57f7\u884c\u8acb\u6c42\uff1a<\/strong>\u6839\u64da\u914d\u7f6e\uff0cNginx \u53ef\u80fd\u6703\u76f4\u63a5\u8fd4\u56de\u975c\u614b\u6587\u4ef6\uff0c\u6216\u5c07\u8acb\u6c42\u8f49\u767c\u5230\u5f8c\u7aef\u61c9\u7528\u7a0b\u5e8f\uff08\u5982 PHP\u3001Python \u6216 Node.js\uff09\u3002\u5982\u679c\u662f\u975c\u614b\u6587\u4ef6\uff0cNginx \u6703\u76f4\u63a5\u5f9e\u6587\u4ef6\u7cfb\u7d71\u4e2d\u8b80\u53d6\u4e26\u8fd4\u56de\uff1b\u5982\u679c\u662f\u52d5\u614b\u8acb\u6c42\uff0c\u5247\u6703\u901a\u904e FastCGI\u3001uWSGI \u6216\u5176\u4ed6\u5354\u8b70\u8207\u5f8c\u7aef\u670d\u52d9\u5668\u9032\u884c\u901a\u4fe1\u3002<\/li>\n<li><strong>\u8fd4\u56de\u97ff\u61c9\uff1a<\/strong>Nginx \u5c07\u8655\u7406\u7d50\u679c\uff08\u7121\u8ad6\u662f\u975c\u614b\u6587\u4ef6\u9084\u662f\u5f8c\u7aef\u61c9\u7528\u7684\u97ff\u61c9\uff09\u8fd4\u56de\u7d66\u7528\u6236\u7684\u700f\u89bd\u5668\u3002\u9019\u500b\u904e\u7a0b\u4e2d\uff0cNginx \u6703\u6dfb\u52a0\u76f8\u61c9\u7684 HTTP \u97ff\u61c9\u982d\uff0c\u4e26\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<\/ol>\n<h2 id=\"%e8%ab%8b%e6%b1%82%e8%99%95%e7%90%86%e7%9a%84%e7%a4%ba%e4%be%8b-nDtNFJLYxj\">\u8acb\u6c42\u8655\u7406\u7684\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 Nginx \u914d\u7f6e\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u8655\u7406\u975c\u614b\u6587\u4ef6\u8acb\u6c42\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n\n    location \/api {\n        proxy_pass http:\/\/backend_server;\n    }\n}<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u7576\u7528\u6236\u8acb\u6c42 <code>http:\/\/example.com\/<\/code> \u6642\uff0cNginx \u6703\u5f9e <code>\/var\/www\/html<\/code> \u76ee\u9304\u4e2d\u67e5\u627e\u975c\u614b\u6587\u4ef6\u3002\u5982\u679c\u8acb\u6c42\u7684\u662f <code>\/api<\/code>\uff0c\u5247 Nginx \u6703\u5c07\u8acb\u6c42\u8f49\u767c\u5230\u5f8c\u7aef\u670d\u52d9\u5668 <code>http:\/\/backend_server<\/code>\u3002<\/p>\n<h2 id=\"%e6%80%a7%e8%83%bd%e5%84%aa%e5%8c%96-nDtNFJLYxj\">\u6027\u80fd\u512a\u5316<\/h2>\n<p>Nginx \u5728\u8655\u7406 HTTP \u8acb\u6c42\u6642\uff0c\u9084\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6027\u80fd\u512a\u5316\u7684\u9078\u9805\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u7de9\u5b58\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u7de9\u5b58\u914d\u7f6e\uff1a<\/p>\n<pre><code>location \/ {\n    proxy_cache my_cache;\n    proxy_pass http:\/\/backend_server;\n}<\/code><\/pre>\n<p>\u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0cNginx \u5c07\u5c0d\u4f86\u81ea\u5f8c\u7aef\u670d\u52d9\u5668\u7684\u97ff\u61c9\u9032\u884c\u7de9\u5b58\uff0c\u5f9e\u800c\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u7684\u8acb\u6c42\u6b21\u6578\uff0c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-nDtNFJLYxj\">\u7d50\u8ad6<\/h2>\n<p>Nginx \u662f\u4e00\u6b3e\u5f37\u5927\u7684 HTTP \u8acb\u6c42\u8655\u7406\u5de5\u5177\uff0c\u5176\u9ad8\u6548\u7684\u8acb\u6c42\u8655\u7406\u6d41\u7a0b\u548c\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u9805\u4f7f\u5176\u6210\u70ba\u8a31\u591a\u7db2\u7ad9\u7684\u9996\u9078\u3002\u7121\u8ad6\u662f\u975c\u614b\u6587\u4ef6\u9084\u662f\u52d5\u614b\u8acb\u6c42\uff0cNginx \u90fd\u80fd\u5920\u5feb\u901f\u800c\u6e96\u78ba\u5730\u8655\u7406\uff0c\u4e26\u63d0\u4f9b\u512a\u8cea\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc Nginx \u7684\u4f7f\u7528\u6709\u8208\u8da3\uff0c\u6216\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u6599\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Nginx \u5982\u4f55\u8655\u7406 HTTP \u8acb\u6c42\u7684\u904e\u7a0b\uff0c\u6df1\u5165\u4e86\u89e3\u5176\u67b6\u69cb\u8207\u904b\u4f5c\u539f\u7406\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51041","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51041"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51041\/revisions"}],"predecessor-version":[{"id":51042,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51041\/revisions\/51042"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}