{"id":3694,"date":"2019-01-08T15:08:39","date_gmt":"2019-01-08T07:08:39","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3694"},"modified":"2019-01-08T15:08:39","modified_gmt":"2019-01-08T07:08:39","slug":"%e9%9a%be%e5%80%92%e4%b8%80%e5%88%87%e4%bc%97%e7%94%9f%e7%9a%84-nginx-%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%ef%bc%8c%e6%8c%87%e4%bb%a4%e5%92%8c%e6%8c%87%e4%bb%a4%e5%9d%97%e8%af%a6%e8%a7%a3%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3694","title":{"rendered":"\u96be\u5012\u4e00\u5207\u4f17\u751f\u7684 nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u4ee4\u548c\u6307\u4ee4\u5757\u8be6\u89e3\uff01"},"content":{"rendered":"<p>\n\t\u57fa\u672c\u4e0a\u6bcf\u4e2a\u8f6f\u4ef6\u6216\u6846\u67b6\u90fd\u63d0\u4f9b\u7684\u6709\u914d\u7f6e\u6587\u4ef6\u3002\u6bd4\u5982\uff0cTomcat \u6709\u914d\u7f6e\u6587\u4ef6\uff0cApache \u4e5f\u6709\uff0cSpring Boot \u4e5f\u6709\uff0cnginx \u4e5f\u4e0d\u4f8b\u5916\u3002\u5176\u4e2d nginx \u7684\u914d\u7f6e\u6587\u4ef6\u6700\u8fc7\u4e8e\u590d\u6742\uff0c\u5176\u5b9e\u4e5f\u4e0d\u590d\u6742\uff0c\u56e0\u4e3a\u4f60\u6ca1\u5b8c\u5168\u7406\u89e3 nginx \u7684\u914d\u7f6e\u8bed\u6cd5\uff0c\u7b49\u4f60\u7406\u89e3\u540e\uff0c\u4f1a\u53d1\u73b0\u539f\u6765\u662f\u5982\u6b64\u7684\u7b80\u5355\u3002\n<\/p>\n<p>\n\tNginx \u7684\u914d\u7f6e\u8bed\u6cd5\uff0c\u5927\u6982\u6709\u4e0b\u9762 7 \u4e2a\u89c4\u5219\u6784\u6210\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Nginx \u7684\u914d\u7f6e\u8bed\u6cd5\u89c4\u5219\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fyz6vdpfh9j20q20c6wjc.jpg\" style=\"width: 938px;height: 438px\" \/>\n<\/p>\n<p>\n\t\u6bcf\u4e2a\u914d\u7f6e\u6587\u4ef6\u90fd\u7531\u6307\u4ee4\u5757\u548c\u6307\u4ee4\u6784\u6210\u3002\u6307\u4ee4\u5757\u662f\u7531 {} \u5927\u62ec\u53f7\u6784\u6210\uff0c\u4e00\u4e2a\u6307\u4ee4\u5757\u5185\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u6307\u4ee4\u3002\u6bcf\u4e2a\u6307\u4ee4\u4ee5 ; \u5206\u53f7\u7ed3\u5c3e\u3002\n<\/p>\n<p>\n\t\u6307\u4ee4\u4e0e\u53c2\u6570\u4e4b\u95f4\u4ee5\u7a7a\u683c\u5206\u5272\uff0c\u591a\u4e2a\u7a7a\u683c\u4e5f\u53ef\u4ee5\u3002# \u662f\u7528\u6765\u6ce8\u91ca\u7684\uff0c# \u884c\u540e\u9762\u7684\u5168\u4e3a\u6ce8\u91ca\uff0c# \u4ee3\u8868\u7684\u662f\u5355\u884c\u6ce8\u91ca\u3002\n<\/p>\n<p>\n\t$ \u7b26\u5408\u4ee3\u8868\u53d8\u91cf\uff0c\u53d8\u91cf\u6709\u81ea\u5b9a\u4e49\u53d8\u91cf\u548c\u7cfb\u7edf\u63d0\u4f9b\u7684\u53d8\u91cf\u3002\u90e8\u5206\u6307\u4ee4\u7684\u53c2\u6570\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6bd4\u5982\uff1alocation \u6307\u4ee4\u3002\n<\/p>\n<p>\n\tinclude \u8bed\u53e5\uff0c\u6216\u8005\u8bf4 include \u6307\u4ee4\u5141\u8bb8\u5f15\u5165\u591a\u4e2a\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6\u3002\n<\/p>\n<p>\n\t\u5177\u4f53\u6bcf\u4e2a\u6307\u4ee4\u7684\u53c2\u6570\u662f\u4ec0\u4e48\uff1f\u51e0\u4e2a\u53c2\u6570\uff1f\u662f\u5426\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff1f\u7b49\u90fd\u662f\u7531\u5177\u4f53\u7684\u6a21\u5757\u51b3\u5b9a\u7684\u3002\n<\/p>\n<p>\n\t\u5e38\u89c1\u7684\u6307\u4ee4\u5757\u6709 4 \u4e2a\uff0c\u5206\u522b\u662f\uff1ahttp \u6307\u4ee4\u3001server \u6307\u4ee4\u3001location \u6307\u4ee4\u3001upstream \u6307\u4ee4\u3002\u638c\u63e1\u8fd9 4 \u4e2a\u57fa\u672c\u4e0a\u5c31\u53ef\u4ee5\u5929\u4e0b\u901a\u5403\uff01\n<\/p>\n<p>\n\tnginx \u7684\u5404\u4e2a\u6a21\u5757\u7ec4\u5408\u5f62\u6210\u4e86\u5176\u5f3a\u5927\u7684\u5904\u7406\u80fd\u529b\uff0c\u800c\u6bcf\u4e2a\u6a21\u5757\u53ea\u5b9e\u73b0\u4e00\u4e2a\u7279\u5b9a\u7684\u529f\u80fd\u3002\u6bd4\u5982\u9650\u6d41\u529f\u80fd\u7531\u6a21\u5757 ngx_http_limit_conn_module \u6216\u8005\u81ea\u5b9a\u4e49\u6a21\u5757\u5b9e\u73b0 ngx_http_limit_req_module\uff1bfastcgi \u8f6c\u53d1\u529f\u80fd\u7531\u6a21\u5757 ngx_http_fastcgi_module \u5b9e\u73b0\uff1bproxy \u8f6c\u53d1\u529f\u80fd\u7531 ngx_http_proxy_module\uff08\u5f53\u7136\u8f6c\u53d1\u529f\u80fd\u7684\u5b9e\u73b0\u8fd8\u5fc5\u987b\u6709\u6a21\u5757 ngx_http_upstream_module\uff09\u3002\n<\/p>\n<p>\n\t\u5f53\u6211\u4eec\u914d\u7f6e\u4e86\u6307\u4ee4 proxy_pass \u6216\u8005 fastcgi_pass \u65f6\uff0c\u8be5\u6307\u4ee4\u5e94\u8be5\u7531\u54ea\u4e2a\u6a21\u5757\u6765\u89e3\u6790\u5462\uff1f\u663e\u7136\u5e94\u8be5\u7531\u5b9e\u73b0\u6b64\u529f\u80fd\u7684\u6a21\u5757\u6765\u89e3\u6790\u3002\u5373 nginx \u914d\u7f6e\u6587\u4ef6\u7684\u89e3\u6790\u662f\u5206\u6563\u5230\u5404\u4e2a\u6a21\u5757\u7684\u3002\n<\/p>\n<p>\n\t\u6bcf\u4e2a\u6a21\u5757\u90fd\u6709\u4e00\u4e2a commands \u6570\u7ec4\uff0c\u5b58\u50a8\u8be5\u6a21\u5757\u53ef\u4ee5\u89e3\u6790\u7684\u6240\u6709\u914d\u7f6e\u6307\u4ee4\u3002\u6307\u4ee4\u7ed3\u6784\u4f53\u7531 ngx_command_t \u5b9a\u4e49\uff1a\n<\/p>\n<pre class=\"brush:cpp;\">\r\nstruct ngx_command_s {\r\n    ngx_str_t             name;\r\n    ngx_uint_t            type;\r\n    char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);\r\n    ngx_uint_t            conf;\r\n    ngx_uint_t            offset;\r\n    void                 *post;\r\n};<\/pre>\n<p>\n\t\u4e0a\u9762\u7ed3\u6784\u4f53\u89e3\u91ca\u5982\u4e0b\uff1a\n<\/p>\n<ul>\n<li>\n\t\tname\uff1a\u914d\u7f6e\u6307\u4ee4\u540d\u79f0\uff0c\u5982&ldquo;proxy_pass&rdquo;\uff1b\n\t<\/li>\n<li>\n\t\ttype\uff1a\u6307\u4ee4\u7c7b\u578b\uff0c\u53ef\u4ee5\u5c06\u6307\u4ee4\u7c7b\u578b\u5206\u4e3a\u4e24\u7c7b\u30021 \u662f\u8bf4\u660e\u6307\u4ee4\u53ef\u4ee5\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u6bd4\u5982\u914d\u7f6e\u6587\u4ef6\uff08\u53ea\u80fd\u5728\u914d\u7f6e\u6587\u4ef6\u6700\u5916\u5c42\uff0c\u4e0d\u80fd\u51fa\u73b0\u5728\u4efb\u4f55\u6307\u4ee4\u5757\u5185\u90e8\uff09\uff0chttp\u6307\u4ee4\u5757\uff0c\u6216\u8005 events \u6307\u4ee4\u5757\uff0c\u6216\u8005 server \u6307\u4ee4\u5757\uff0c\u6216\u8005 location \u6307\u4ee4\u5757\uff0c\u6216\u8005\u30022 \u662f\u6309\u7167\u53c2\u6570\u5206\u7c7b\u3002\n\t<\/li>\n<li>\n\t\tset\uff1a\u5904\u7406\u51fd\u6570\uff0c\u5f53\u8bfb\u53d6\u5230\u8be5\u914d\u7f6e\u6307\u4ee4\u65f6\uff0c\u4f1a\u6267\u884c\u6b64\u51fd\u6570\uff1b\n\t<\/li>\n<li>\n\t\tconf \u548c offset\uff1a\u4e24\u8005\u5176\u5b9e\u90fd\u8868\u793a\u7684\u662f\u504f\u79fb\u91cf\uff0c\u4f46\u662f\u7528\u5904\u4e0d\u540c\uff0c\u89e3\u6790\u6307\u4ee4\u65f6\u4f1a\u8be6\u8ff0\uff0c\u8fd9\u91cc\u6682\u65f6\u8df3\u8fc7\u3002\n\t<\/li>\n<li>\n\t\tpost\uff1a\u53ef\u4ee5\u6307\u5411\u591a\u79cd\u7ed3\u6784\uff0c\u4e0d\u540c\u6307\u4ee4\u53ef\u80fd\u4e0d\u540c\uff0c\u5927\u591a\u90fd\u4e3a NUll\uff0c\u89e3\u6790\u5230\u5177\u4f53\u6307\u4ee4\u65f6\u4f1a\u8be6\u8ff0\uff0c\u8fd9\u91cc\u540c\u6837\u8df3\u8fc7\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u5e38\u7528\u7684 type \u6307\u4ee4\u7c7b\u578b\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"nginx \u6307\u4ee4\u7ed3\u6784\u4f53 type \u7c7b\u578b\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fyz6xlvh4oj20m80ag78t.jpg\" style=\"width: 800px;height: 376px\" \/>\n<\/p>\n<p>\n\t\u5e38\u7528\u7684 4 \u4e2a\u6307\u4ee4\u5757\u5bf9\u5e94\u7684\u6a21\u5757\u90fd\u975e\u5e38\u7684\u590d\u6742\uff0c\u5177\u4f53\u53c2\u89c1 nginx \u7684\u6e90\u4ee3\u7801\u5c31\u77e5\u9053\u4e86\u3002\u672c\u6587\u4e3b\u8981\u9610\u8ff0\u4e00\u4e2a\u4e8b\u5b9e\uff0cnginx \u7684\u914d\u7f6e\u6587\u4ef6\u5e76\u4e0d\u590d\u6742\uff0c\u5168\u90fd\u6709\u6307\u4ee4\u6216\u6307\u4ee4\u5757\u6784\u6210\uff0c\u6478\u901a\u5b83\u7684\u6784\u6210\u5373\u53ef\u3002\u540e\u9762\u6211\u4eec\u4f1a\u901a\u8fc7\u5177\u4f53\u7684\u5b9e\u4f8b\u6765\u5b66\u4e60\u6bcf\u4e2a\u6307\u4ee4\u7684\u7528\u6cd5\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3694\">\u96be\u5012\u4e00\u5207\u4f17\u751f\u7684 nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u4ee4\u548c\u6307\u4ee4\u5757\u8be6\u89e3\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u4e0a\u6bcf\u4e2a\u8f6f\u4ef6\u6216\u6846\u67b6\u90fd\u63d0\u4f9b\u7684\u6709\u914d\u7f6e\u6587\u4ef6\u3002\u6bd4\u5982\uff0cTomcat \u6709\u914d\u7f6e\u6587\u4ef6\uff0cApache \u4e5f\u6709\uff0cSpring Bo [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,6],"tags":[1152,313,1154,112,216],"class_list":["post-3694","post","type-post","status-publish","format-standard","hentry","category-ndisdevelop","category-yyzt","tag-nginx","tag-nginx-tfs","tag-tomcat","tag-216"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3694"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3694\/revisions"}],"predecessor-version":[{"id":3695,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3694\/revisions\/3695"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}