{"id":3847,"date":"2019-02-12T13:18:22","date_gmt":"2019-02-12T05:18:22","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3847"},"modified":"2019-02-12T13:18:22","modified_gmt":"2019-02-12T05:18:22","slug":"nginx-%e4%b8%ad%e7%9a%84%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86-proxy_pass-%e9%85%8d%e7%bd%ae%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3847","title":{"rendered":"Nginx \u4e2d\u7684\u53cd\u5411\u4ee3\u7406 proxy_pass \u914d\u7f6e\u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u5bf9\u4e8e Nginx\uff0c\u53ef\u80fd\u6709\u5f88\u591a\u4eba\u7b2c\u4e00\u65f6\u95f4\u80fd\u60f3\u5230\u7684\u5c31\u662f\u5b83\u7684\u53cd\u5411\u4ee3\u7406\u8fd9\u4e00\u7279\u6027\uff0c\u4eca\u5929\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u7b80\u5355\u7684\u5b66\u4e60\u4e00\u4e0b Nginx \u4e2d\u7684\u53cd\u5411\u4ee3\u7406 proxy_pass \u7684\u76f8\u5173\u914d\u7f6e\u7528\u6cd5\u3002\n<\/p>\n<p>\n\t\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u804a\u4e00\u804a\u5565\u662f\u6b63\u5411\u4ee3\u7406\uff0c\u5565\u662f\u53cd\u5411\u4ee3\u7406\u3002\n<\/p>\n<h2>\n\t\u6b63\u5411\u4ee3\u7406<br \/>\n<\/h2>\n<p>\n\t<img decoding=\"async\" alt=\"\u56fe\u89e3\u6b63\u5411\u4ee3\u7406\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g03kc2uj3hj20hx09w75a.jpg\" style=\"width: 645px;height: 356px\" \/>\n<\/p>\n<p>\n\t\u4ece\u4e0a\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\u3002\u6b63\u5411\u4ee3\u7406\u4e2d\uff0cproxy \u548c client \u540c\u5c5e\u4e00\u4e2a LAN\uff0c\u5bf9 server \u900f\u660e\uff1b\u6b63\u5411\u4ee3\u7406\uff0c\u4ee3\u7406\u7684\u662f\u5ba2\u6237\u7aef\uff0c\u4e3a\u5ba2\u6237\u7aef\u6536\u53d1\u8bf7\u6c42\uff0c\u4f7f\u771f\u5b9e\u5ba2\u6237\u7aef\u5bf9\u670d\u52a1\u5668\u4e0d\u53ef\u89c1\u3002\n<\/p>\n<p>\n\t\u6b63\u5411\u4ee3\u7406\u9700\u8981\u4f60\u4e3b\u52a8\u8bbe\u7f6e\u4ee3\u7406\u670d\u52a1\u5668 ip \u6216\u8005\u57df\u540d\u8fdb\u884c\u8bbf\u95ee\uff0c\u7531\u8bbe\u7f6e\u7684\u670d\u52a1\u5668 ip \u6216\u8005\u57df\u540d\u53bb\u83b7\u53d6\u8bbf\u95ee\u5185\u5bb9\u5e76\u8fd4\u56de\u3002\n<\/p>\n<h2>\n\t\u53cd\u5411\u4ee3\u7406<br \/>\n<\/h2>\n<p>\n\t\u7406\u89e3\u4e86\u6b63\u5411\u4ee3\u7406\uff0c\u6211\u4eec\u5728\u6765\u770b\u53cd\u5411\u4ee3\u7406\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u56fe\u89e3\u53cd\u5411\u4ee3\u7406\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g03kd8rvd5j20gv0b00tr.jpg\" style=\"width: 607px;height: 396px\" \/>\n<\/p>\n<p>\n\t\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u53cd\u5411\u4ee3\u7406\u4e2d\uff0cproxy \u548c server \u540c\u5c5e\u4e00\u4e2a LAN\uff0c\u5bf9 client \u900f\u660e\u3002\n<\/p>\n<p>\n\t\u53cd\u5411\u4ee3\u7406\uff0c\u4ee3\u7406\u7684\u662f\u670d\u52a1\u5668\uff0c\u4e3a\u670d\u52a1\u5668\u6536\u53d1\u8bf7\u6c42\uff0c\u4f7f\u771f\u5b9e\u670d\u52a1\u5668\u5bf9\u5ba2\u6237\u7aef\u4e0d\u53ef\u89c1\u3002\n<\/p>\n<p>\n\t\u53cd\u5411\u4ee3\u7406\u4e0d\u9700\u8981\u4f60\u505a\u4efb\u4f55\u8bbe\u7f6e\uff0c\u76f4\u63a5\u8bbf\u95ee\u670d\u52a1\u5668\u771f\u5b9e ip \u6216\u8005\u57df\u540d\uff0c\u4f46\u662f\u670d\u52a1\u5668\u5185\u90e8\u4f1a\u81ea\u52a8\u6839\u636e\u8bbf\u95ee\u5185\u5bb9\u8fdb\u884c\u8df3\u8f6c\u53ca\u5185\u5bb9\u8fd4\u56de\uff0c\u4f60\u4e0d\u77e5\u9053\u5b83\u6700\u7ec8\u8bbf\u95ee\u7684\u662f\u54ea\u4e9b\u673a\u5668\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u6b63\u5411\u4ee3\u7406\u4e0e\u53cd\u5411\u4ee3\u7406\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g03kdzcmlqj209t079wer.jpg\" style=\"width: 353px;height: 261px\" \/>\n<\/p>\n<p>\n\t\u4e0a\u9762\u5bf9\u6b63\u5411\u4ee3\u7406\u548c\u53cd\u5411\u4ee3\u7406\u89e3\u91ca\u5230\u4f4d\u540e\uff0c\u6211\u4eec\u5728\u6765\u8bf4\u4e00\u4e0b\uff0c\u4e3a\u4ec0\u4e48\u9700\u8981\u53cd\u5411\u4ee3\u7406\uff1f\n<\/p>\n<p>\n\t\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u751f\u4ea7\u4e0a\u7684\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u90e8\u7f72\u4e86 A \u5e94\u7528\uff0c\u4e5f\u90e8\u7f72\u4e86 B \u5e94\u7528\u3002\u5f53\u6211\u4eec\u8bbf\u95ee www.xttblog.com \u65f6\uff0c\u8bf7\u6c42\u4f1a\u88ab\u4ea4\u7ed9 A \u5e94\u7528\u7684 6666 \u7aef\u53e3\u5904\u7406\uff1b\u5f53\u6211\u4eec\u8bbf\u95ee www.ndislwf.com \u65f6\uff0c\u8bf7\u6c42\u4f1a\u4ea4\u7ed9 B \u5e94\u7528\u7684 8888 \u7aef\u53e3\u5904\u7406\u3002\u50cf\u8fd9\u6837\uff0c\u540c\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u6709\u591a\u4e2a\u5e94\u7528\u3002\u4f46\u662f\u53ea\u6709\u4e00\u4e2a Nginx\uff0c\u901a\u8fc7\u8bbf\u95ee\u4e0d\u540c\u7684 url \u5c06\u8bf7\u6c42\u4ea4\u7ed9\u4e0d\u540c\u7684\u5e94\u7528\u5904\u7406\u65f6\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5230\u53cd\u5411\u4ee3\u7406\u7684\u529f\u80fd\u3002\n<\/p>\n<p>\n\t\u60f3\u4e00\u60f3\uff0c\u5982\u679c\u6ca1\u6709\u53cd\u5411\u4ee3\u7406\u4f1a\u600e\u6837\uff1f\u6211\u4eec\u4e0d\u80fd\u8bf4\u662f\uff0c\u4e00\u4e2a\u670d\u52a1\u5668\u53ea\u5141\u8bb8\u90e8\u7f72\u4e00\u4e2a\u5e94\u7528\u3002\u6216\u8005\u662f\u8bbf\u95ee\u4e0d\u540c\u7684\u5e94\u7528\u5e26\u4e0a\u4e0d\u540c\u7684\u7aef\u53e3\u5427\u3002\u6240\u4ee5\uff0c\u53cd\u5411\u4ee3\u7406\u5f88\u91cd\u8981\uff01\n<\/p>\n<p>\n\t\u90a3\u4e48 Nginx \u600e\u4e48\u914d\u7f6e\u53cd\u5411\u4ee3\u7406\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u4f7f\u7528 proxy_pass \u6307\u4ee4\u5c31\u53ef\u4ee5\u89e3\u51b3\u4f60\u7684\u95ee\u9898\u3002\n<\/p>\n<p>\n\tnginx \u4e2d\u6709\u4e24\u4e2a\u6a21\u5757\u90fd\u6709 proxy_pass \u6307\u4ee4\u3002\u4e00\u4e2a\u662f ngx_http_proxy_module \u6a21\u5757\uff0c\u4e00\u4e2a\u662f ngx_stream_proxy_module \u6a21\u5757\u3002\n<\/p>\n<p>\n\tngx_http_proxy_module \u4e2d\u7684 proxy_pass \u7528\u6cd5\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\n\u8bed\u6cd5: proxy_pass URL;\r\n\u573a\u666f: location, if in location, limit_except\r\n\u8bf4\u660e: \u8bbe\u7f6e\u540e\u7aef\u4ee3\u7406\u670d\u52a1\u5668\u7684\u534f\u8bae(protocol)\u548c\u5730\u5740(address),\u4ee5\u53calocation\u4e2d\u53ef\u4ee5\u5339\u914d\u7684\u4e00\u4e2a\u53ef\u9009\u7684URI\u3002\r\n  \u534f\u8bae\u53ef\u4ee5\u662f&quot;http&quot;\u6216&quot;https&quot;\u3002\u5730\u5740\u53ef\u4ee5\u662f\u4e00\u4e2a\u57df\u540d\u6216ip\u5730\u5740\u548c\u7aef\u53e3\uff0c\u6216\u8005\u4e00\u4e2a unix-domain socket \u8def\u5f84\u3002  \r\n\u8be6\u89c1\u5b98\u65b9\u6587\u6863: http:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_pass<\/pre>\n<p>\n\tngx_stream_proxy_module \u4e2d\u7684 proxy_pass \u7528\u6cd5\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\n\u8bed\u6cd5: proxy_pass address;\r\n\u573a\u666f: server\r\n\u8bf4\u660e: \u8bbe\u7f6e\u540e\u7aef\u4ee3\u7406\u670d\u52a1\u5668\u7684\u5730\u5740\u3002\r\n  \u8fd9\u4e2a\u5730\u5740(address)\u53ef\u4ee5\u662f\u4e00\u4e2a\u57df\u540d\u6216ip\u5730\u5740\u548c\u7aef\u53e3\uff0c\r\n  \u6216\u8005\u4e00\u4e2a unix-domain socket\u8def\u5f84\u3002  \r\n\u8be6\u89c1\u5b98\u65b9\u6587\u6863: http:\/\/nginx.org\/en\/docs\/stream\/ngx_stream_proxy_module.html#proxy_pass<\/pre>\n<p>\n\t\u4e24\u4e2a proxy_pass \u7684\u5173\u7cfb\u548c\u533a\u522b\n<\/p>\n<p>\n\t\u5728\u4e24\u4e2a\u6a21\u5757\u4e2d\uff0c\u4e24\u4e2a proxy_pass \u90fd\u662f\u7528\u6765\u505a\u540e\u7aef\u4ee3\u7406\u7684\u6307\u4ee4\u3002\n<\/p>\n<ul>\n<li>\n\t\tngx_stream_proxy_module \u6a21\u5757\u7684 proxy_pass \u6307\u4ee4\u53ea\u80fd\u5728 server \u6bb5\u4f7f\u7528\u4f7f\u7528, \u53ea\u9700\u8981\u63d0\u4f9b\u57df\u540d\u6216 ip \u5730\u5740\u548c\u7aef\u53e3\u3002\u53ef\u4ee5\u7406\u89e3\u4e3a\u7aef\u53e3\u8f6c\u53d1\uff0c\u53ef\u4ee5\u662f tcp \u7aef\u53e3\uff0c\u4e5f\u53ef\u4ee5\u662f udp \u7aef\u53e3\u3002\n\t<\/li>\n<li>\n\t\tngx_http_proxy_module \u6a21\u5757\u7684 proxy_pass \u6307\u4ee4\u9700\u8981\u5728 location \u6bb5\uff0clocation \u4e2d\u7684 if \u6bb5\uff0climit_except \u6bb5\u4e2d\u4f7f\u7528\uff0c\u5904\u7406\u9700\u8981\u63d0\u4f9b\u57df\u540d\u6216 ip \u5730\u5740\u548c\u7aef\u53e3\u5916\uff0c\u8fd8\u9700\u8981\u63d0\u4f9b\u534f\u8bae\uff0c\u5982&quot;http&quot;\u6216&quot;https&quot;\uff0c\u8fd8\u6709\u4e00\u4e2a\u53ef\u9009\u7684 uri \u53ef\u4ee5\u914d\u7f6e\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u5173\u4e8e ngx_http_proxy_module \u4e2d proxy_pass \u7684\u4f7f\u7528\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\u3002\n<\/p>\n<p>\n\t\u5047\u8bbe\u8bbf\u95ee http:\/\/192.168.8.8\/proxy\/test.html\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n# \u7b2c\u4e00\u79cd\r\nlocation \/proxy\/ {\r\n\u3000\u3000proxy_pass http:\/\/127.0.0.1:81\/;\r\n}\r\n#\u4f1a\u88ab\u4ee3\u7406\u5230http:\/\/127.0.0.1:81\/test.html\u8fd9\u4e2aurl\r\n\r\n#\u7b2c\u4e8c\u79cd\r\nlocation \/proxy\/ {\r\n\u3000\u3000proxy_pass http:\/\/127.0.0.1:81;\r\n}\r\n#\u4f1a\u88ab\u4ee3\u7406\u5230http:\/\/127.0.0.1:81\/proxy\/test.html\u8fd9\u4e2aurl\r\n\r\n#\u7b2c\u4e09\u79cd\r\nlocation  \/proxy\/ {\r\n  proxy_pass http:\/\/127.0.0.1:81\/ftlynx\/;\r\n}\r\n#\u4f1a\u88ab\u4ee3\u7406\u5230http:\/\/127.0.0.1:81\/ftlynx\/test.html \u8fd9\u4e2a url\u3002\r\n\r\n#\u7b2c\u56db\u79cd\u60c5\u51b5(\u76f8\u5bf9\u4e8e\u7b2c\u4e09\u79cd\uff0c\u6700\u540e\u5c11\u4e00\u4e2a \/ )\uff1a\r\nlocation  \/proxy\/ {\r\n  proxy_pass http:\/\/127.0.0.1:81\/ftlynx;\r\n}\r\n#\u4f1a\u88ab\u4ee3\u7406\u5230 http:\/\/127.0.0.1:81\/ftlynxtest.html \u8fd9\u4e2a url<\/pre>\n<p>\n\tngx_stream_proxy_module \u6a21\u5757\u7684 proxy_pass \u6307\u4ee4\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nserver {\r\n    listen 127.0.0.1:12345;\r\n    proxy_pass 127.0.0.1:8080;\r\n}\r\nserver {\r\n    listen 12345;\r\n    proxy_connect_timeout 1s;\r\n    proxy_timeout 1m;\r\n    proxy_pass example.com:12345;\r\n}\r\nserver {\r\n    listen 53 udp;\r\n    proxy_responses 1;\r\n    proxy_timeout 20s;\r\n    proxy_pass dns.example.com:53;\r\n}\r\nserver {\r\n    listen [::1]:12345;\r\n    proxy_pass unix:\/tmp\/stream.socket;\r\n}<\/pre>\n<p>\n\t\u5173\u4e8e proxy_pass \u6307\u4ee4\u7684\u4ecb\u7ecd\u5c31\u5148\u5230\u8fd9\u91cc\u3002\u66f4\u591a\u914d\u7f6e\u548c\u529f\u80fd\u4f7f\u7528\u8bf7\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff01<\/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=3847\">Nginx \u4e2d\u7684\u53cd\u5411\u4ee3\u7406 proxy_pass \u914d\u7f6e\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e Nginx\uff0c\u53ef\u80fd\u6709\u5f88\u591a\u4eba\u7b2c\u4e00\u65f6\u95f4\u80fd\u60f3\u5230\u7684\u5c31\u662f\u5b83\u7684\u53cd\u5411\u4ee3\u7406\u8fd9\u4e00\u7279\u6027\uff0c\u4eca\u5929\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u7b80\u5355\u7684\u5b66\u4e60\u4e00\u4e0b Ngi [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1152,313,1154,1155,1156],"class_list":["post-3847","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-nginx","tag-nginx-tfs","tag-proxy_cache_lock","tag-proxy_cache_min_uses"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3847","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=3847"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3847\/revisions"}],"predecessor-version":[{"id":3848,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3847\/revisions\/3848"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}