nginx负载均衡二:配置
配置方法一(可用):
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负载均衡二:配置的更多相关文章
- nginx负载均衡简单配置
nginx负载均衡简单配置准备三台虚拟机来做这个实验:192.168.232.132 web服务器192.168.232.133 web服务器192.168.232.134 ...
- nginx负载均衡及配置
nginx负载均衡及配置 1 负载均衡概述 负载均衡由来是因为当一台服务器单位时间内的访问量很大时,此时服务器的压力也会很大,当超过自身承受能力时,服务器就会崩溃.为避免让服务器崩溃,用户拥有更好的体 ...
- nginx负载均衡常见问题配置信息
nginx为后端web服务器(apache,nginx,tomcat,weblogic)等做反向代理 几台后端web服务器需要考虑文件共享,数据库共享,session共享问题.文件共享可以使用nfs, ...
- nginx 负载均衡简单配置
配置要求: 三台服务器 127.0.0.1 主负载(把访问请求分给主机池) 127.0.0.2 主机2 127.0.0.3 主机3 第一步: 配置127.0.0.1 ...
- Nginx负载均衡各种配置方式
Nginx负载均衡 - 小刚qq - 博客园http://www.cnblogs.com/xiaogangqq123/archive/2011/03/04/1971002.html Module ng ...
- Nginx负载均衡NFS配置
Nginx配置 首先在两台服务器上部署同一个项目,例如下: 测试网站节点1: http://192.168.168.61/nfstest/ 测试网站节点2: http://192.168.64.145 ...
- NGINX负载均衡缓存配置
环境:VMware-Workstation-12-Pro,Windows-10,CentOS-7.5,Xshell5 1 概述 如果我们的架构是前端负载均衡后端WEB集群时,可以开启nginx的缓存功 ...
- php nginx 负载均衡简单配置过程
负载均衡 负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 简单了解一下什么是负载均衡,单从字面上的意思来理解就可以解 ...
- window下nginx负载均衡简单配置-----权重的实现
下面介绍一个在window下的nginx的负载均衡配置. 需要你在你的电脑上跑两个tomcat.一个8080,一个9080. 需要一个nginx服务器. 需要修改本机的host 注意:我们这里配置不会 ...
随机推荐
- BZOJ4374 : Little Elephant and Boxes
设$f[i][j][k]$表示前$i$个物品买了$j$个,消耗$k$个钻石,最少花多少钱,可以通过简单的DP求出. 枚举拥有的钻石数以及最多能购买的物品数的下界,那么钱数的下界是定值. 将$n$个箱子 ...
- 【11.5校内测试】【倒计时5天】【DP】【二分+贪心check】【推式子化简+线段树】
Solution 非常巧妙的建立DP方程. 据dalao们说题目明显暗示根号复杂度??(反正我是没看出来 因为每次分的块大小一定不超过$\sqrt n$,要不然直接每个位置开一个块答案都才为$n$. ...
- 使用gulp对js、css、img进行合并压缩
1 概述 最新使用AngularJS框架做单页面项目,其中包括了很多库的和自已写的js.css.img文件,这些文件都不大,但是数量众多,导致web请求文件过多,一次性加载时比较慢.有尝试过使用异步加 ...
- Structured Streaming教程(1) —— 基本概念与使用
近年来,大数据的计算引擎越来越受到关注,spark作为最受欢迎的大数据计算框架,也在不断的学习和完善中.在Spark2.x中,新开放了一个基于DataFrame的无下限的流式处理组件--Structu ...
- Layout Inflation :Unconditional layout, inflation from view adapter
Layout inflation在Android上下文环境下转换XML文件成View结构对象的时候需要用到. LayoutInflater这个对象在Android的SDK中很常见,但是你绝对没想到竟然 ...
- python测试开发django-47.xadmin上传图片和文件
前言 xadmin上传图片和上传文件功能 依赖环境 如果没安装Pillow的话,会有报错:practise.Upload.upload_image: (fields.E210) Cannot use ...
- python测试开发django-45.xadmin添加小组件报错解决
前言 xadmin首页上有个添加小组件按钮,打开的时候会报错"render() got an unexpected keyword argument 'renderer'" 环境: ...
- VS2010链接TFS遇见错误:TF204017,没有访问工作区域,需要一个或者多个必须权限
最近刚刚搭建好服务器,然后准备将VSS源代码迁移到TFS源代码管理服务器上面.在我本机先用的服务器帐号来上传初始化源代码数据库,然后我又用自己的帐号进行迁出代码的时候发生的异常. 造成上述错误,主要是 ...
- Convolutional Neural Networks: Step by Step
Andrew Ng deeplearning courese-4:Convolutional Neural Network Convolutional Neural Networks: Step by ...
- [Functional Programming] Using Lens to update nested object
For example, in React application, we have initial state; const data = { nextId: 4, todoFilter: 'SHO ...