zoukankan      html  css  js  c++  java
  • Nginx 简单的负载均衡配置示例

    www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP。

      用户访问http://www.s135.com,将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。

      用户访问http://blog.s135.com,将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。

      以下为配置文件nginx.conf:

    user  www www;
    
    worker_processes 10;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    #最大文件描述符
    worker_rlimit_nofile 51200;
    
    events 
    {
          use epoll;
    
          worker_connections 51200;
    }
    
    http 
    {
          include       conf/mime.types;
          default_type  application/octet-stream;
    
          keepalive_timeout 120;
    
          tcp_nodelay on;
    
          upstream  www.s135.com  {
                  server   192.168.1.2:80;
                  server   192.168.1.3:80;
                  server   192.168.1.4:80;
                  server   192.168.1.5:80;
          }
    
          upstream  blog.s135.com  {
                  server   192.168.1.7:8080;
                  server   192.168.1.7:8081;
                  server   192.168.1.7:8082;
          }
    
          server
          {
                  listen  80;
                  server_name  www.s135.com;
    
                  location / {
                           proxy_pass        http://www.s135.com;
                           proxy_set_header   Host             $host;
                           proxy_set_header   X-Real-IP        $remote_addr;
                           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                  }
    
                  log_format  www_s135_com  '$remote_addr - $remote_user [$time_local] $request '
                                    '"$status" $body_bytes_sent "$http_referer" '
                                    '"$http_user_agent" "$http_x_forwarded_for"';
                  access_log  /data1/logs/www.log  www_s135_com;
          }
    
          server
          {
                  listen  80;
                  server_name  blog.s135.com;
    
                  location / {
                           proxy_pass        http://blog.s135.com;
                           proxy_set_header   Host             $host;
                           proxy_set_header   X-Real-IP        $remote_addr;
                           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                  }
    
                  log_format  blog_s135_com  '$remote_addr - $remote_user [$time_local] $request '
                                    '"$status" $body_bytes_sent "$http_referer" '
                                    '"$http_user_agent" "$http_x_forwarded_for"';
                  access_log  /data1/logs/blog.log  blog_s135_com;
          }
    }

    引用地址:http://www.s135.com/post/306/

  • 相关阅读:
    (一二二)核心动画进阶
    1089. Insert or Merge (25)
    (一二一)核心动画基础
    (一二〇)CALayer的一些特性
    (一一九)通过CALayer实现阴影、圆角、边框和3D变换
    1086. Tree Traversals Again (25)
    POJ 2610:Dog & Gopher
    模拟内存分配(链表实现)
    圣诞树后能找到我的记忆
    YTU 2797: 复仇者联盟之关灯
  • 原文地址:https://www.cnblogs.com/phpfans/p/3559784.html
Copyright © 2011-2022 走看看