zoukankan      html  css  js  c++  java
  • Nginx 负载均衡动静分离配置

    nginx.conf
    1.通过目录进行分离。
    #静态服务器

    upstream static_pools

      {
              server 10.0.0.9:80 weight=5 max_fails=10 fail_timeout=10s;
                  }
    #动态服务器
        upstream dynamic_pools

                  {
              server 10.0.0.10:80 weight=5 max_fails=10 fail_timeout=10s;

                       }
    #上传服务器
        upstream upload_pools                    

    {
              server 10.0.0.10:80 weight=5 max_fails=10 fail_timeout=10s;

                       }          

    #server标签配置:

    server {

               listen   80;

    #访问的域名

               server_name www.xxxxx.com;

    #动态服务器

         location / {

               proxy_pass http://dynamic_pools;

               proxy_set_header Host    $host;

               proxy_set_header X-Forwarded-For $remote_addr;

                 }

    #静态服务器
      location /image/ {

               proxy_pass http://static_pools;

               proxy_set_header Host    $host;

               proxy_set_header X-Forwarded-For $remote_addr;

                    }

    #上传服务器
      location /upload/ {

               proxy_pass http://upload_pools;

               proxy_set_header Host    $host;

               proxy_set_header X-Forwarded-For $remote_addr;

                    }

      }
    clip_image001

    clip_image003

    server {

               listen   80;

    #访问的域名

               server_name www.xxxxx.com;

    #通过扩展名访问

    location ~ {

               proxy_pass http://static_pools;

               proxy_set_header Host    $host;

               proxy_set_header X-Forwarded-For $remote_addr;

                    }

    clip_image004

    用于部分程序不支持的浏览器。

    location /

    {

    #当使用IE浏览器时显示动态内容

    if ($http_user_agent ~* "MSIE")

    {

    proxy_pass http://dynamic_pools;

    }

    #当使用火狐浏览器时显示静态内容

    if ($http_user_agent ~* "Firefox")

    {

    proxy_pass http://static_pools;

    }

    #其它使用默认

    proxy_pass http://dynamic_pools;

    include proxy.conf;

    }

    clip_image005

    clip_image006

    proxy_redirect off;

    proxy_set_header Host $host;

    proxy_set_header X-Forwarded-For $remote_addr;

    proxy_connect_timeout 60;

    proxy_send_timeout 60;

    proxy_read_timeout 60;

    proxy_buffer_size 4k;

    proxy_buffers 4 32k;

    proxy_busy_buffers_size 64k;

    proxy_temp_file_write_size 64k;

    手机用户和浏览器用户:

    当访问同一个域名不同终端的时候,显示内容的服务器不一致

    location /

    {

    #当使用Android终端时访问安卓服务器

    if ($http_user_agent ~* "android")

    {

    proxy_pass http://android_pools;

    }

    #当使用苹果终端时访问苹果服务器

    if ($http_user_agent ~* "iphone")

    {

    proxy_pass http://iphone_pools;

    }

    #其它使用默认

    proxy_pass http://dynamic_pools;

    include proxy.conf;

    }

    北丐洪七公--Jeff
    Dignity comes from strength, strength comes from struggle!
    本文版权归作者和博客园共有,欢迎转载,未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    三维拓扑排序好题hdu3231
    hdu1811 拓扑排序+并查集缩点
    拓扑排序基础 hdu1258,hdu2647
    uva11827 处理下输入
    poj2116 模拟题
    exgcd求解同余方程的最小正整数解 poj1061 poj2115
    java Web应用配置log4j日志记录
    response.sendRedirect()重新定向的乱码问题
    JavaWeb学习之Servlet(四)----ServletConfig获取配置信息、ServletContext的应用
    JavaWeb学习之Servlet(三)----Servlet的映射匹配问题、线程安全问题
  • 原文地址:https://www.cnblogs.com/wangyifu/p/7202670.html
Copyright © 2011-2022 走看看