{"id":1508,"date":"2020-06-05T21:32:47","date_gmt":"2020-06-05T13:32:47","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1508"},"modified":"2020-06-05T21:32:47","modified_gmt":"2020-06-05T13:32:47","slug":"nginx%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1508","title":{"rendered":"Nginx\u53cd\u5411\u4ee3\u7406"},"content":{"rendered":"<div>\n<h2>1. \u7b80\u4ecb<\/h2>\n<p><strong>Nginx<\/strong> \u662f\u5f00\u6e90\u7684\u8f7b\u91cf\u7ea7 Web \u670d\u52a1\u5668\u3001\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u5668\u548c HTTP \u7f13\u5b58\u5668\u3002\u5176\u7279\u70b9\u662f\u9ad8\u5e76\u53d1\uff0c\u9ad8\u6027\u80fd\u548c\u4f4e\u5185\u5b58 \u3002<br \/>\n<strong>Nginx<\/strong> \u4e13\u4e3a\u6027\u80fd\u4f18\u5316\u800c\u5f00\u53d1\uff0c\u6027\u80fd\u662f\u5176\u6700\u91cd\u8981\u7684\u8003\u91cf\uff0c\u5b9e\u73b0\u4e0a\u975e\u5e38\u6ce8\u91cd\u6548\u7387\uff0c\u80fd\u7ecf\u53d7\u9ad8\u8d1f\u8f7d\u7684\u8003\u9a8c\uff0c\u6700\u5927\u80fd\u652f\u6301 50000 \u4e2a\u5e76\u53d1\u8fde\u63a5\u6570\u3002 Nginx \u8fd8\u652f\u6301\u70ed\u90e8\u7f72\uff0c\u5b83\u7684\u4f7f\u7528\u7279\u522b\u5bb9\u6613\uff0c\u51e0\u4e4e\u53ef\u4ee5\u505a\u5230 7&#215;24 \u5c0f\u65f6\u4e0d\u95f4\u65ad\u8fd0\u884c\u3002<\/p>\n<h2>2. \u53cd\u5411\u4ee3\u7406<\/h2>\n<h3>2.1 \u6b63\u5411\u4ee3\u7406<\/h3>\n<p><strong>Nginx<\/strong> \u4e0d\u4ec5\u53ef\u4ee5\u505a\u53cd\u5411\u4ee3\u7406\uff0c\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\uff0c\u8fd8\u80fd\u7528\u505a\u6b63\u5411\u4ee3\u7406\u6765\u8fdb\u884c\u4e0a\u7f51\u7b49\u529f\u80fd\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"699\\\" data-height=\\\"318\\\"><img class=\\\"aligncenter\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-5eb5ab539f750899.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/699\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-5eb5ab539f750899.png\\\" data-original-width=\\\"699\\\" data-original-height=\\\"318\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"25624\\\" data-image-index=\\\"0\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\" style=\\\"text-align: center;\\\">\u6b63\u5411\u4ee3\u7406\u539f\u7406\u56fe<\/div>\n<\/div>\n<h3>2.2 \u53cd\u5411\u4ee3\u7406<\/h3>\n<p>\u5ba2\u6237\u7aef\u5bf9\u4ee3\u7406\u670d\u52a1\u5668\u662f\u65e0\u611f\u77e5\u7684\uff0c\u5ba2\u6237\u7aef\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u914d\u7f6e\uff0c\u7528\u6237\u53ea\u8bf7\u6c42\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u9009\u62e9\u76ee\u6807\u670d\u52a1\u5668\uff0c\u83b7\u53d6\u6570\u636e\u540e\u518d\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u548c\u76ee\u6807\u670d\u52a1\u5668\u5bf9\u5916\u800c\u8a00\u5c31\u662f\u4e00\u4e2a\u670d\u52a1\u5668\uff0c\u53ea\u662f\u66b4\u9732\u7684\u662f\u4ee3\u7406\u670d\u52a1\u5668\u5730\u5740\uff0c\u800c\u9690\u85cf\u4e86\u771f\u5b9e\u670d\u52a1\u5668\u7684IP\u5730\u5740\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"791\\\" data-height=\\\"382\\\"><img class=\\\"aligncenter\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-fb24d6922ba0cd2e.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/791\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-fb24d6922ba0cd2e.png\\\" data-original-width=\\\"791\\\" data-original-height=\\\"382\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"28622\\\" data-image-index=\\\"1\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\" style=\\\"text-align: center;\\\">\u53cd\u5411\u4ee3\u7406\u539f\u7406\u56fe<\/div>\n<\/div>\n<h2>3. \u8d1f\u8f7d\u5747\u8861<\/h2>\n<p>\u5c06\u539f\u5148\u8bf7\u6c42\u96c6\u4e2d\u5230\u5355\u4e2a\u670d\u52a1\u5668\u4e0a\u7684\u60c5\u51b5\u6539\u4e3a\u589e\u52a0\u670d\u52a1\u5668\u7684\u6570\u91cf\uff0c\u7136\u540e\u5c06\u8bf7\u6c42\u5206\u53d1\u5230\u5404\u4e2a\u670d\u52a1\u5668\u4e0a\uff0c\u5c06\u8d1f\u8f7d\u5206\u53d1\u5230\u4e0d\u540c\u7684\u670d\u52a1\u5668\uff0c\u5373\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"780\\\" data-height=\\\"380\\\"><img class=\\\"aligncenter\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-035d77b6b387ff4d.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/780\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-035d77b6b387ff4d.png\\\" data-original-width=\\\"780\\\" data-original-height=\\\"380\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"28247\\\" data-image-index=\\\"2\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\" style=\\\"text-align: center;\\\">\u8d1f\u8f7d\u5747\u8861\u539f\u7406\u56fe<\/div>\n<\/div>\n<h2>4. \u52a8\u9759\u5206\u79bb<\/h2>\n<p>\u4e3a\u4e86\u52a0\u5feb\u7f51\u7ad9\u7684\u89e3\u6790\u901f\u5ea6\uff0c\u53ef\u4ee5\u628a\u9759\u6001\u9875\u9762\u548c\u52a8\u6001\u9875\u9762\u7531\u4e0d\u540c\u7684\u670d\u52a1\u5668\u6765\u89e3\u6790\uff0c\u52a0\u5feb\u89e3\u6790\u901f\u5ea6\uff0c\u964d\u4f4e\u539f\u6765\u5355\u4e2a\u670d\u52a1\u5668\u7684\u538b\u529b\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"745\\\" data-height=\\\"328\\\"><img class=\\\"aligncenter\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-faae04da8e262ac0.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/745\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-faae04da8e262ac0.png\\\" data-original-width=\\\"745\\\" data-original-height=\\\"328\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"30762\\\" data-image-index=\\\"3\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\" style=\\\"text-align: center;\\\">\u52a8\u9759\u5206\u79bb\u539f\u7406\u56fe<\/div>\n<\/div>\n<h2>5. \u9ad8\u53ef\u7528<\/h2>\n<p>\u4e3a\u4e86\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u7528\u6027\u548c\u5bb9\u9519\u80fd\u529b\uff0c\u53ef\u4ee5\u589e\u52a0 nginx \u670d\u52a1\u5668\u7684\u6570\u91cf\uff0c\u5f53\u4e3b\u670d\u52a1\u5668\u53d1\u751f\u6545\u969c\u6216\u5b95\u673a\uff0c\u5907\u4efd\u670d\u52a1\u5668\u53ef\u4ee5\u7acb\u5373\u5145\u5f53\u4e3b\u670d\u52a1\u5668\u8fdb\u884c\u4e0d\u95f4\u65ad\u5de5\u4f5c\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"770\\\" data-height=\\\"350\\\"><img class=\\\"aligncenter\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-29747c1981881fd9.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/770\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15942529-29747c1981881fd9.png\\\" data-original-width=\\\"770\\\" data-original-height=\\\"350\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"42457\\\" data-image-index=\\\"4\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\" style=\\\"text-align: center;\\\">\u9ad8\u53ef\u7528\u539f\u7406\u56fe<\/div>\n<\/div>\n<h2>6. Nginx\u914d\u7f6e\u6587\u4ef6<\/h2>\n<h3>6.1 \u6587\u4ef6\u7ed3\u6784<\/h3>\n<p>Nginx \u914d\u7f6e\u6587\u4ef6\u7531\u4e09\u90e8\u5206\u7ec4\u6210\u3002<\/p>\n<div>\n<pre>...              #\u5168\u5c40\u5757\nevents {         #events\u5757\n   ...\n}\nhttp      #http\u5757\n{\n    ...   #http\u5168\u5c40\u5757\n    server        #server\u5757\n    {\n        ...       #server\u5168\u5c40\u5757\n        location [PATTERN]   #location\u5757\n        {\n            ...\n        }\n        location [PATTERN]\n        {\n            ...\n        }\n    }\n    server\n    {\n      ...\n    }\n    ...     #http\u5168\u5c40\u5757\n}\n<\/pre>\n<\/div>\n<ul>\n<li><strong>\u7b2c\u4e00\u90e8\u5206 \u5168\u5c40\u5757<\/strong><br \/>\n\u4e3b\u8981\u8bbe\u7f6e\u4e00\u4e9b\u5f71\u54cd nginx \u670d\u52a1\u5668\u6574\u4f53\u8fd0\u884c\u7684\u914d\u7f6e\u6307\u4ee4\u3002<br \/>\n\u6bd4\u5982\uff1a worker_processes 1; \uff0c worker_processes \u503c\u8d8a\u5927\uff0c\u53ef\u4ee5\u652f\u6301\u7684\u5e76\u53d1\u5904\u7406\u91cf\u5c31\u8d8a\u591a\u3002<\/li>\n<li><strong>\u7b2c\u4e8c\u90e8\u5206 events\u5757<\/strong><br \/>\nevents \u5757\u6d89\u53ca\u7684\u6307\u4ee4\u4e3b\u8981\u5f71\u54cdNginx\u670d\u52a1\u5668\u4e0e\u7528\u6237\u7684\u7f51\u7edc\u8fde\u63a5\u3002<br \/>\n\u6bd4\u5982\uff1a worker_connections 1024; \uff0c\u652f\u6301\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002<\/li>\n<li><strong>\u7b2c\u4e09\u90e8\u5206 http\u5757<\/strong><br \/>\nhttp \u5757\u53c8\u5305\u62ec http \u5168\u5c40\u5757\u548c server \u5757\uff0c\u662f\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u6700\u9891\u7e41\u7684\u90e8\u5206\uff0c\u5305\u62ec\u914d\u7f6e\u4ee3\u7406\u3001\u7f13\u5b58\u3001\u65e5\u5fd7\u5b9a\u4e49\u7b49\u7edd\u5927\u591a\u6570\u529f\u80fd\u3002<\/p>\n<ul>\n<li><strong>server\u5757<\/strong>\uff1a\u914d\u7f6e\u865a\u62df\u4e3b\u673a\u7684\u76f8\u5173\u53c2\u6570\u3002<\/li>\n<li><strong>location\u5757<\/strong>\uff1a\u914d\u7f6e\u8bf7\u6c42\u8def\u7531\uff0c\u4ee5\u53ca\u5404\u79cd\u9875\u9762\u7684\u5904\u7406\u60c5\u51b5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>6.2 \u914d\u7f6e\u6587\u4ef6<\/h3>\n<div>\n<pre>########### \u6bcf\u4e2a\u6307\u4ee4\u5fc5\u987b\u6709\u5206\u53f7\u7ed3\u675f\u3002#################\n#user administrator administrators;  #\u914d\u7f6e\u7528\u6237\u6216\u8005\u7ec4\uff0c\u9ed8\u8ba4\u4e3anobody nobody\u3002\n#worker_processes 2;  #\u5141\u8bb8\u751f\u6210\u7684\u8fdb\u7a0b\u6570\uff0c\u9ed8\u8ba4\u4e3a1\n#pid \/nginx\/pid\/nginx.pid;   #\u6307\u5b9anginx\u8fdb\u7a0b\u8fd0\u884c\u6587\u4ef6\u5b58\u653e\u5730\u5740\nerror_log log\/error.log debug;  #\u5236\u5b9a\u65e5\u5fd7\u8def\u5f84\uff0c\u7ea7\u522b\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u53ef\u4ee5\u653e\u5165\u5168\u5c40\u5757\uff0chttp\u5757\uff0cserver\u5757\uff0c\u7ea7\u522b\u4ee5\u6b64\u4e3a\uff1adebug|info|notice|warn|error|crit|alert|emerg\nevents {\n    accept_mutex on;   #\u8bbe\u7f6e\u7f51\u8def\u8fde\u63a5\u5e8f\u5217\u5316\uff0c\u9632\u6b62\u60ca\u7fa4\u73b0\u8c61\u53d1\u751f\uff0c\u9ed8\u8ba4\u4e3aon\n    multi_accept on;  #\u8bbe\u7f6e\u4e00\u4e2a\u8fdb\u7a0b\u662f\u5426\u540c\u65f6\u63a5\u53d7\u591a\u4e2a\u7f51\u7edc\u8fde\u63a5\uff0c\u9ed8\u8ba4\u4e3aoff\n    #use epoll;      #\u4e8b\u4ef6\u9a71\u52a8\u6a21\u578b\uff0cselect|poll|kqueue|epoll|resig|\/dev\/poll|eventport\n    worker_connections  1024;    #\u6700\u5927\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u4e3a512\n}\nhttp {\n    include       mime.types;   #\u6587\u4ef6\u6269\u5c55\u540d\u4e0e\u6587\u4ef6\u7c7b\u578b\u6620\u5c04\u8868\n    default_type  application\/octet-stream; #\u9ed8\u8ba4\u6587\u4ef6\u7c7b\u578b\uff0c\u9ed8\u8ba4\u4e3atext\/plain\n    #access_log off; #\u53d6\u6d88\u670d\u52a1\u65e5\u5fd7\n    log_format myFormat \\'$remote_addr\u2013$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for\\'; #\u81ea\u5b9a\u4e49\u683c\u5f0f\n    access_log log\/access.log myFormat;  #combined\u4e3a\u65e5\u5fd7\u683c\u5f0f\u7684\u9ed8\u8ba4\u503c\n    sendfile on;   #\u5141\u8bb8sendfile\u65b9\u5f0f\u4f20\u8f93\u6587\u4ef6\uff0c\u9ed8\u8ba4\u4e3aoff\uff0c\u53ef\u4ee5\u5728http\u5757\uff0cserver\u5757\uff0clocation\u5757\u3002\n    sendfile_max_chunk 100k;  #\u6bcf\u4e2a\u8fdb\u7a0b\u6bcf\u6b21\u8c03\u7528\u4f20\u8f93\u6570\u91cf\u4e0d\u80fd\u5927\u4e8e\u8bbe\u5b9a\u7684\u503c\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u5373\u4e0d\u8bbe\u4e0a\u9650\u3002\n    keepalive_timeout 65;  #\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba4\u4e3a75s\uff0c\u53ef\u4ee5\u5728http\uff0cserver\uff0clocation\u5757\u3002\n    upstream mysvr {\n      server 127.0.0.1:7878;\n      server 192.168.10.121:3333 backup;  #\u70ed\u5907\n    }\n    error_page 404 https:\/\/www.baidu.com; #\u9519\u8bef\u9875\n    server {\n        keepalive_requests 120; #\u5355\u8fde\u63a5\u8bf7\u6c42\u4e0a\u9650\u6b21\u6570\u3002\n        listen       4545;   #\u76d1\u542c\u7aef\u53e3\n        server_name  127.0.0.1;   #\u76d1\u542c\u5730\u5740\n        location  ~*^.+$ {       #\u8bf7\u6c42\u7684url\u8fc7\u6ee4\uff0c\u6b63\u5219\u5339\u914d\uff0c~\u4e3a\u533a\u5206\u5927\u5c0f\u5199\uff0c~*\u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002\n           #root path;  #\u6839\u76ee\u5f55\n           #index vv.txt;  #\u8bbe\u7f6e\u9ed8\u8ba4\u9875\n           proxy_pass  http:\/\/mysvr;  #\u8bf7\u6c42\u8f6c\u5411mysvr \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868\n           deny 127.0.0.1;  #\u62d2\u7edd\u7684ip\n           allow 172.18.5.54; #\u5141\u8bb8\u7684ip\n        }\n    }\n}\n<\/pre>\n<\/div>\n<h2>7.\u914d\u7f6e\u5b9e\u4f8b<\/h2>\n<h3>7.1 \u53cd\u5411\u4ee3\u7406<\/h3>\n<h4>7.1.1 \u6848\u4f8b\u4e00<\/h4>\n<p><strong>\u5b9e\u73b0\u6548\u679c\uff1a<\/strong><br \/>\n\u5728\u6d4f\u89c8\u5668\u8f93\u5165IP\u5730\u5740, \u4ece nginx \u670d\u52a1\u5668\u8df3\u8f6c\u5230 linux \u7cfb\u7edf tomcat \u4e3b\u9875\u9762\u3002<br \/>\n<strong>\u5177\u4f53\u914d\u7f6e\uff1a<\/strong><\/p>\n<div>\n<pre>    server {\n        listen       80;\n        server_name  192.168.4.32;   #\u76d1\u542c\u5730\u5740\n        location  \/ {\n           root html;  #\/html\u76ee\u5f55\n           proxy_pass http:\/\/127.0.0.1:8080;  #\u8bf7\u6c42\u8f6c\u5411\n           index  index.html index.htm;      #\u8bbe\u7f6e\u9ed8\u8ba4\u9875\n        }\n    }\n<\/pre>\n<\/div>\n<h4>7.1.2 \u6848\u4f8b\u4e8c<\/h4>\n<p><strong>\u5b9e\u73b0\u6548\u679c\uff1a<\/strong><br \/>\n\u6839\u636e\u5728\u6d4f\u89c8\u5668\u8f93\u5165\u7684\u8def\u5f84\u4e0d\u540c\uff0c\u8df3\u8f6c\u5230\u4e0d\u540c\u7aef\u53e3\u7684\u670d\u52a1\u4e2d\u3002<br \/>\n<strong>\u5177\u4f53\u914d\u7f6e\uff1a<\/strong><\/p>\n<div>\n<pre>    server {\n        listen       9000;\n        server_name  192.168.4.32;   #\u76d1\u542c\u5730\u5740\n        location  ~ \/example1\/ {\n           proxy_pass http:\/\/127.0.0.1:5000;\n        }\n        location  ~ \/example2\/ {\n           proxy_pass http:\/\/127.0.0.1:8080;\n        }\n    }\n<\/pre>\n<\/div>\n<p><strong>location<\/strong> \u6307\u4ee4\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li><strong>~ :<\/strong> \u8868\u793auri\u5305\u542b\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e14\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li><strong>~* :<\/strong> \u8868\u793auri\u5305\u542b\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e14\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li><strong>= :<\/strong> \u8868\u793auri\u4e0d\u542b\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8981\u6c42\u4e25\u683c\u5339\u914d\u3002<\/li>\n<\/ul>\n<h3>7.2 \u8d1f\u8f7d\u5747\u8861<\/h3>\n<h4>7.2.1 \u6848\u4f8b\u4e00<\/h4>\n<p><strong>\u5b9e\u73b0\u6548\u679c\uff1a<\/strong><br \/>\n\u5728\u6d4f\u89c8\u5668\u5730\u5740\u680f\u8f93\u5165 <em><a href=\\\"https:\/\/links.jianshu.com\/go?to=http%3A%2F%2F192.168.4.32%2Fexample%2Fa.html\\\" target=\\\"_blank\\\" rel=\\\"noopener noreferrer\\\">http:\/\/192.168.4.32\/example\/a.html<\/a><\/em> \uff0c\u5e73\u5747\u5230 5000 \u548c 8080 \u7aef\u53e3\u4e2d\uff0c\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u6548\u679c\u3002<br \/>\n<strong>\u5177\u4f53\u914d\u7f6e\uff1a<\/strong><\/p>\n<div>\n<pre>    upstream myserver {\n      server 192.167.4.32:5000;\n      server 192.168.4.32:8080;\n    }\n    server {\n        listen       80;   #\u76d1\u542c\u7aef\u53e3\n        server_name  192.168.4.32;   #\u76d1\u542c\u5730\u5740\n        location  \/ {\n           root html;  #html\u76ee\u5f55\n           index index.html index.htm;  #\u8bbe\u7f6e\u9ed8\u8ba4\u9875\n           proxy_pass  http:\/\/myserver;  #\u8bf7\u6c42\u8f6c\u5411 myserver \u5b9a\u4e49\u7684\u670d\u52a1\u5668\u5217\u8868\n        }\n    }\n<\/pre>\n<\/div>\n<p><strong>nginx \u5206\u914d\u670d\u52a1\u5668\u7b56\u7565<\/strong><\/p>\n<ul>\n<li><strong>\u8f6e\u8be2<\/strong>\uff08\u9ed8\u8ba4\uff09<br \/>\n\u6309\u8bf7\u6c42\u7684\u65f6\u95f4\u987a\u5e8f\u4f9d\u6b21\u9010\u4e00\u5206\u914d\uff0c\u5982\u679c\u670d\u52a1\u5668down\u6389\uff0c\u80fd\u81ea\u52a8\u5254\u9664\u3002<\/li>\n<li><strong>\u6743\u91cd<\/strong><br \/>\nweight \u8d8a\u9ad8\uff0c\u88ab\u5206\u914d\u7684\u5ba2\u6237\u7aef\u8d8a\u591a\uff0c\u9ed8\u8ba4\u4e3a 1\u3002\u6bd4\u5982\uff1a<\/p>\n<div>\n<pre>      upstream myserver {\n        server 192.167.4.32:5000 weight=10;\n        server 192.168.4.32:8080 weight=5;\n      }\n<\/pre>\n<\/div>\n<\/li>\n<li><strong>ip<\/strong><br \/>\n\u6309\u8bf7\u6c42 ip \u7684 hash \u503c\u5206\u914d\uff0c\u6bcf\u4e2a\u8bbf\u5ba2\u56fa\u5b9a\u8bbf\u95ee\u4e00\u4e2a\u540e\u7aef\u670d\u52a1\u5668\u3002<\/p>\n<div>\n<pre>      upstream myserver {\n        ip_hash;\n        server 192.167.4.32:5000;\n        server 192.168.4.32:8080;\n      }\n<\/pre>\n<\/div>\n<\/li>\n<li><strong>fair<\/strong><br \/>\n\u6309\u540e\u7aef\u670d\u52a1\u5668\u7684\u54cd\u5e94\u65f6\u95f4\u6765\u5206\u914d\uff0c\u54cd\u5e94\u65f6\u95f4\u77ed\u7684\u4f18\u5148\u5206\u914d\u5230\u8bf7\u6c42\u3002<\/p>\n<div>\n<pre>      upstream myserver {\n        fair;\n        server 192.167.4.32:5000;\n        server 192.168.4.32:8080;\n      }\n<\/pre>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. \u7b80\u4ecb Nginx \u662f\u5f00\u6e90\u7684\u8f7b\u91cf\u7ea7 Web \u670d\u52a1\u5668\u3001\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u5668\u548c HTTP \u7f13\u5b58\u5668\u3002\u5176 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1508\"> <span class=\"screen-reader-text\">Nginx\u53cd\u5411\u4ee3\u7406<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[99,125],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"1. \u7b80\u4ecb Nginx \u662f\u5f00\u6e90\u7684\u8f7b\u91cf\u7ea7 Web \u670d\u52a1\u5668\u3001\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u5668\u548c HTTP \u7f13\u5b58\u5668\u3002\u5176&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1508"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1508"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1508\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1508"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}