接上篇nginx配置,然后再准备两台web服务器:

nginx服务器:192.168.0.241

web1:192.168.0.141

web2:192.168.0.142

一、两台web服务器先安装http:

[root@host1 ~]# yum -y install httpd
[root@host1 ~]# /etc/init.d/httpd start
[root@host1 ~]# echo "Hello,I'm 192.168.0.141" > /var/www/html/index.html
[root@host1 ~]# curl http://192.168.0.141
Hello,I'm 192.168.0.141
[root@host2 ~]# yum -y install httpd
[root@host1 ~]# /etc/init.d/httpd start
[root@host2 ~]# echo "Hello,I'm 192.168.0.142" > /var/www/html/index.html
[root@host2 ~]# curl http://192.168.0.142
Hello,I'm 192.168.0.142
#注意先看下服务器上是否有安装http,如httpd启动不起来,看下是否80端口在被占用

二、nginx服务器配置负载均衡:

[root@host3 conf]# cd /usr/local/nginx/conf/
[root@host3 conf]# vim nginx.conf
…………
http { #定义源服务器组
upstream team {
server 192.168.0.141;
server 192.168.0.142;
}
…………
…………
server {
#定义监听端口
listen ;
#定义访问域名
server_name www.load.com;
location / {
#调用服务器组
proxy_pass http://team;
root html;
index index.html;
}
}
…………
…………
}
:wq
[root@host3 conf]# nginx -s reload
#继续添加nginx服务器访问域名
[root@host3 conf]# vim /etc/hosts
…………
192.168.0.241 www.nginx1.com www.nginx2.com www.load.com
:wq
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.141
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.141
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142

注意:如果访问不了看下是否防火墙限制了,8080端口如被占用可改为其他端口

三、设置权重:

#接上面的配置
[root@host3 conf]# vim nginx.conf
…………
http { upstream team {
#设置权重参数,机器的性能越好,可以设置参数越大
server 192.168.0.141 weight=;
server 192.168.0.142 weight=;
}
…………
:wq
[root@host3 conf]# nginx -s reload
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.141
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.141
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142
[root@host3 conf]# curl http://www.load.com:8080
Hello,I'm 192.168.0.142

附:nginx优化参数(http模块)

server_tokens off;      #添加此行,不显示nginx具体版本号

include       mime.types;   #设定mime类型,类型由mime.type文件定义

sendfile        on;      #提升nginx读文件性能

tcp_nodelay     on;     #关闭tcp的缓延迟发送数据,即立即相应

keepalive_timeout  65;   #连接超时时间

gzip  on;        #开启gzip压缩

gzip_min_length 1000;   #小于1000k的不压缩,越压缩越大

gzip_comp_level 4;      #压缩级别是4(1-9个级别)

gzip_types ……           #允许压缩的类型,/usr/local/nginx/conf/mime.types有类型

client_header_buffer_size 1k;      #设定请求缓存

large_client_header_buffers 4 4k;    #最大请求缓存个数与容量

#先根据client_header_buffer分配,如果不够,再根据large值分配

#设定虚拟主机配置:

    server {
        #侦听80端口
        listen    80;
        #定义使用 www.nginx.com访问
        server_name  www.nginx.com;
        #定义服务器的默认网站根目录位置
        root html;
        #设定访问日志
        access_log  logs/nginx.access.log  main;
        #默认请求
        location / {
        #定义首页索引文件的名称
            index index.php index.html index.htm;  
        }
   # 定义错误提示页面

        error_page   500 502 503 504 /50x.html;
        location = /50x.html {
        }

  #禁止访问 .htxxx 文件

            location ~ /.ht {
            deny all;
  }
}

nginx负载均衡及详细配置的更多相关文章

  1. Nginx负载均衡的详细配置及使用案例详解.

    感谢看过这一些列博文和评论的小伙伴, 我把自己所看到的学到的拿到这里来分享是想和大家一起学习进步, 想听听园友给出的意见, 也是对自己学习过程的一个总结. 技术无止境, 我们仍需努力! 1,话不多说, ...

  2. [项目构建 十三]babasport Nginx负载均衡的详细配置及使用案例详解.

    在这里再次说明下, 这个项目是从网上 找到的一套学习资料, 自己在 空闲时间学习了这些东西. 这里面的code当然会有很多不完善的地方, 但是确实也能学到很多新东西.感谢看过这一些列博文和评论的小伙伴 ...

  3. Nginx负载均衡的详细配置 + Keepalived使用

    1,话不多说, 这里我们来说下很重要的负载均衡, 那么什么是负载均衡呢? 由于目前现有网络的各个核心部分随着业务量的提高,访问量和数据流量的快速增长,其处理能力和计算强度也相应地增大,使得单一的服务器 ...

  4. Nginx记录-nginx 负载均衡5种配置方式(转载)

    nginx 负载均衡5种配置方式 1.轮询(默认)   每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除.  2.weight 指定轮询几率,weight和访问比率成 ...

  5. nginx 负载均衡5种配置方式

    nginx 负载均衡5种配置方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比, ...

  6. nginx负载均衡之入门配置

    先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可以解释N台服务器平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况.那么负载均衡的前提就是要有多台服务器才能实现,也就是两台以上 ...

  7. 干货 | Nginx负载均衡原理及配置实例

    一个执着于技术的公众号 Nginx系列导读 给小白的 Nginx 10分钟入门指南 Nginx编译安装及常用命令 完全卸载nginx的详细步骤 Nginx 配置文件详解 理解正向代理与反向代理的区别 ...

  8. nginx负载均衡tomcat和配置ssl

    目录 tomcat 组件功能 engine host context connector service server valve logger realm UserDatabaseRealm 工作流 ...

  9. nginx负载均衡二:配置

    配置方法一(可用): upstream tomcatserver1 { server ; server 192.168.70.172; server 192.168.70.173 down; serv ...

随机推荐

  1. python 面向对象设计思想发展史

    这篇主要说的是程序设计思想发展历史,分为概述和详细发展历史 一,概述 1940年以前:面向机器 最早的程序设计都是采用机器语言来编写的,直接使用二进制码来表示机器能够识别和执行的 指令和数 据.简单来 ...

  2. nyoj VF

    VF 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Vasya is the beginning mathematician. He decided to make ...

  3. vue 手机端开发 小商铺 添加购物车 以及结算 功能

    这个功能绕了我一天!!!            对 就是这个功能  一系列相关联的  四处相关联 现在加班 没时间更 过两天在更

  4. 改变input的placeholder颜色

    input::-webkit-input-placeholder{ color:#666; } input::-ms-input-placeholder{ color:#666; } input::- ...

  5. xxe漏洞检测及代码执行过程

    这两天看了xxe漏洞,写一下自己的理解,xxe漏洞主要针对webservice危险的引用的外部实体并且未对外部实体进行敏感字符的过滤,从而可以造成命令执行,目録遍历等.首先存在漏洞的web服务一定是存 ...

  6. ORA-00379 缓冲池 DEFAULT 中无法提供 32K 块大小的空闲缓冲区

    (一)问题 今天在使用Pl/sql developer查看表空间大小的时候,报错误:ORA-00379 缓冲池 DEFAULT 中无法提供 32K 块大小的空闲缓冲区,具体如下图: SQL> s ...

  7. SpringCloud的DataRest(一)

    一.概念与定义 Spring Data Rest 基于Spring Data的repository,可以把 repository 自动输出为REST资源, 这样做的好处: 可以免去大量的 contro ...

  8. Linux网络配置(setup)

    新装的Linux系统,想要快捷的网络配置,首选setup命令. 1.设置setup为中文. echo LANG="zh_CN.UTF-8" > /etc/sysconfig/ ...

  9. mybatis的generator中xml配置问题

    <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.sung.risk.model.biz" t ...

  10. python 进程 线程

    进程 线程 操作系统 为什么要有操作系统? 操作系统:操作系统是一个用来协调,管理和控制计算机硬件和软件资源的系统程序.位于底层硬件与应用软件之间 工作方式:向下管理硬件 向上提供接口 切换 1.出现 ...