Site updated: 2022-09-27 15:13:02

This commit is contained in:
qinglong
2022-09-27 15:13:02 +08:00
parent edf027ae42
commit 4fcf6f00cc
42 changed files with 311 additions and 41 deletions

View File

@@ -6,6 +6,18 @@
"description": "hito的博客",
"home_page_url": "https://blog.jingxiyuan.cn",
"items": [
{
"id": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/",
"url": "https://blog.jingxiyuan.cn/2022/09/27/nginx%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%85%8D%E7%BD%AE/",
"title": "nginx负载均衡配置",
"date_published": "2022-09-27T06:45:00.000Z",
"content_html": "<h2 id=\"nginx负载均衡配置\"><a class=\"anchor\" href=\"#nginx负载均衡配置\">#</a> nginx 负载均衡配置</h2>\n<ol>\n<li>轮询(默认)</li>\n</ol>\n<p><em>每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器 down 掉,能自动剔除。</em></p>\n<pre><code class=\"language-yum\">upstream my_server &#123;\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n&#125;\n\nserver &#123;\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / &#123;\n\t\tproxy_pass http://my_server;\n\t&#125;\n\t\n&#125;\n</code></pre>\n<ol start=\"2\">\n<li>weight 权重策略</li>\n</ol>\n<p><em>weight 代表权重,默认为 1权重越高被分配的客户端越多指定轮询几率。weight 和访问比率成正比,用于后端服务器性能不均的情况。</em></p>\n<pre><code class=\"language-yum\">upstream my_server &#123;\n\tserver 192.168.0.2:8080 weight=1;\n\tserver 192.168.0.3:8080 weight=2;\n&#125;\n\nserver &#123;\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / &#123;\n\t\tproxy_pass http://my_server;\n\t&#125;\n\t\n&#125;\n</code></pre>\n<ol start=\"3\">\n<li>ip_hash</li>\n</ol>\n<p><em>每个请求按访问 ip 的 hash 结果分配,这样每个访客固定访问一个后端服务器,可以解决 session 的问题。</em></p>\n<pre><code class=\"language-yum\">upstream my_server &#123;\n\tip_hash;\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n&#125;\n\nserver &#123;\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / &#123;\n\t\tproxy_pass http://my_server;\n\t&#125;\n\t\n&#125;\n</code></pre>\n<ol start=\"4\">\n<li>fair (第三方)</li>\n</ol>\n<p><em>按后端服务器的响应时间来分配请求,响应时间短的优先分配。</em></p>\n<pre><code class=\"language-yum\">upstream my_server &#123;\n\tserver 192.168.0.2:8080;\n\tserver 192.168.0.3:8080;\n\tfair;\n&#125;\n\nserver &#123;\n\tlisten 80;\n\tserver_name 192.168.0.1;\n\n\t# Path to the root of your installation\n\tlocation / &#123;\n\t\tproxy_pass http://my_server;\n\t&#125;\n\t\n&#125;\n</code></pre>\n<ol start=\"5\">\n<li>动静分离</li>\n</ol>\n<p><em>把静态的资源比如图片cssjs 等先加载到 Nginx 的服务器里。</em></p>\n",
"tags": [
"技术分享",
"nginx",
"负载均衡"
]
},
{
"id": "https://blog.jingxiyuan.cn/2022/09/26/%E8%A7%A3%E5%86%B3Hexo-Shoka%E8%83%8C%E6%99%AF%E9%9F%B3%E4%B9%90%E6%97%A0%E6%B3%95%E6%92%AD%E6%94%BE%E7%9A%84%E9%97%AE%E9%A2%98/",
"url": "https://blog.jingxiyuan.cn/2022/09/26/%E8%A7%A3%E5%86%B3Hexo-Shoka%E8%83%8C%E6%99%AF%E9%9F%B3%E4%B9%90%E6%97%A0%E6%B3%95%E6%92%AD%E6%94%BE%E7%9A%84%E9%97%AE%E9%A2%98/",