配置方法一(可用):

upstream  tomcatserver1  {
server 192.168.70.170 weight=;
server 192.168.70.172;
server 192.168.70.173 down;
server 192.168.70.174;
server 192.168.70.175 backup;
} server {
listen ;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver1
;   index index.html index.htm; } }

通过以上配置,便可以实现,在访问192.168.70.169这个网站时,由于配置了proxy_pass地址,所有请求都会先通过nginx反向代理服务器,在服务器将请求转发给目的主机时,读取upstream为 tomcatsever1的地址,读取分发策略,配置tomcat1权重为3,所以nginx会将大部分请求发送给49服务器上的tomcat1,也就是192.168.70.170;较少部分给tomcat2来实现有条件的负载均衡,当然这个条件就是服务器1、2的硬件指数处理请求能力。

1)down:表示单前的server暂时不参与负载

2)Weight:默认为1.weight越大,负载的权重就越大。

3)max_fails:允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误

4)fail_timeout:max_fails 次失败后,暂停的时间。

5)Backup:其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

配置方法二(可用):

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on;   // 位置1:upstream
upstream 192.168.70.169 {
  server 192.168.70.170;
  server 192.168.70.172;
  #ip_hash;
} server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html;
index index.html index.htm index.php; } #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ \.php$ {
root html;
#fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;        //位置2:proxy_pass 
proxy_pass http://192.168.70.169;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

nginx负载均衡二:配置的更多相关文章

  1. nginx负载均衡简单配置

    nginx负载均衡简单配置准备三台虚拟机来做这个实验:192.168.232.132        web服务器192.168.232.133        web服务器192.168.232.134 ...

  2. nginx负载均衡及配置

    nginx负载均衡及配置 1 负载均衡概述 负载均衡由来是因为当一台服务器单位时间内的访问量很大时,此时服务器的压力也会很大,当超过自身承受能力时,服务器就会崩溃.为避免让服务器崩溃,用户拥有更好的体 ...

  3. nginx负载均衡常见问题配置信息

    nginx为后端web服务器(apache,nginx,tomcat,weblogic)等做反向代理 几台后端web服务器需要考虑文件共享,数据库共享,session共享问题.文件共享可以使用nfs, ...

  4. nginx 负载均衡简单配置

    配置要求: 三台服务器 127.0.0.1       主负载(把访问请求分给主机池) 127.0.0.2       主机2 127.0.0.3       主机3 第一步: 配置127.0.0.1 ...

  5. Nginx负载均衡各种配置方式

    Nginx负载均衡 - 小刚qq - 博客园http://www.cnblogs.com/xiaogangqq123/archive/2011/03/04/1971002.html Module ng ...

  6. Nginx负载均衡NFS配置

    Nginx配置 首先在两台服务器上部署同一个项目,例如下: 测试网站节点1: http://192.168.168.61/nfstest/ 测试网站节点2: http://192.168.64.145 ...

  7. NGINX负载均衡缓存配置

    环境:VMware-Workstation-12-Pro,Windows-10,CentOS-7.5,Xshell5 1 概述 如果我们的架构是前端负载均衡后端WEB集群时,可以开启nginx的缓存功 ...

  8. php nginx 负载均衡简单配置过程

    负载均衡 负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 简单了解一下什么是负载均衡,单从字面上的意思来理解就可以解 ...

  9. window下nginx负载均衡简单配置-----权重的实现

    下面介绍一个在window下的nginx的负载均衡配置. 需要你在你的电脑上跑两个tomcat.一个8080,一个9080. 需要一个nginx服务器. 需要修改本机的host 注意:我们这里配置不会 ...

随机推荐

  1. python的条件与循环1

    一.if语句 功能 计算机又被称作电脑,意指计算机可以像人脑一样,根据周围环境条件(即expession)的变化做出不同的反应(即执行代码) if语句就是来控制计算机实现这一功能. if语句小结 if ...

  2. win7下一劳永逸地解决触控板禁用的问题

    win7下一劳永逸地解决触控板禁用的问题--有鼠标时触摸板不再可用, 没鼠标时才启用 下载Synaptics触摸板驱动并安装(去官网或驱动之家都可以) →重启 开始→运行→框内输入 regedit 点 ...

  3. Java内存区域与内存溢出异常--运行时数据区

    Java与C之间有一堵由内存动态分配和垃圾收集技术所围成的“高墙”. C.C++程序开发在内存管理区域,既拥有每一个对象的“所有权”,又担负着每一个对象声明开始到终结的责任,而Java在虚拟机自动管理 ...

  4. wordpress:搭建个人博客

    如果是自己玩可以使用虚拟机练习一下,想放到线上就买台服务器 安装Mysql 新买的云服务器,需要检测系统是否自带安装mysql yum list installed | grep mysql 如果发现 ...

  5. thinkphp5 学习笔记

    一.开发规范: 二.API: 1.数据输出:新版的控制器输出采用 Response 类统一处理,而不是直接在控制器中进行输出,通过设置 default_return_type 就可以自动进行数据转换处 ...

  6. oracle 列相减——(Oracle分析函数Lead(),Lag())

    lag和lead函数,用于取出数据的前n行的数据和后n行的数据,当然要和over(order by)一起组合 其实这2个函数的作用非常好理解,Lead()就是取当前顺序的下一条记录,相对Lag()就是 ...

  7. php中__call() 和 __callStatic方法的使用

    __call 与__callStatic 魔法方法是php5.3后新增的,二者的应用场景: 1.当要调用的方法不存在或权限不足时,会自动调用__call 方法. 2.当调用的静态方法不存在或权限不足时 ...

  8. android: 动态加载碎片布局的技巧

    虽然动态添加碎片的功能很强大,可以解决很多实际开发中的问题,但是它毕竟只是在 一个布局文件中进行一些添加和替换操作.如果程序能够根据设备的分辨率或屏幕大小在运 行时来决定加载哪个布局,那我们可发挥的空 ...

  9. Scala:Next Steps in Scala

    Array val greetStrings = new Array[String](3) greetStrings(0) = "Hello" greetStrings(1) = ...

  10. python实战--csdn博客专栏下载器

    打算利用业余时间好好研究Python的web框架--web.py,深入剖析其实现原理,体会web.py精巧之美.但在研究源码的基础上至少得会用web.py.思前想后,没有好的Idea,于是打算开发一个 ...