一、下载Nginx
http://nginx.org/download/nginx-1.0.8.zip
解压到C:\nginx目录下
二、在两台服务器上分别建一个网站:
S1:192.168.16.35:8054
S2:192.168.16.16:8089
二、找到目录
C:\nginx\conf\nginx.conf
打开nginx.conf
配置如下:

#使用的用户和组,window下不指定
#user  nobody;
#指定工作衍生进程数(一般等于CPU总和数或总和数的两倍,例如两个四核CPU,则总和数为8)
worker_processes  1;
#指定错误日志文件存放路径,错误日志级别可选项为【debug|info|notice|warn|error|crit】
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;
#指定pid存放路径
#pid        logs/nginx.pid;

#工作模式及连接数上限
events {
    #使用网络I/O模型,Linux系统推荐使用epoll模型,FreeBSD系统推荐使用kqueue;window下不指定 
    #use epoll; 
    #允许的连接数
    worker_connections  1024;
}

#设定http服务器,利用他的反向代理功能提供负载均衡支持  
http {
    #设定mime类型
    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;
    log_format main '$remote_addr - $remote_user [$time_local]'    
                                        '"$request" $status $bytes_sent'    
                                        '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"'    
                                        '"$gzip_ratio"';    
    log_format download '$remote_addr - $remote_user [$time_local]'    
                                        '"$request" $status $bytes_sent'    
                                        '"$http_referer" "$http_user_agent"'    
                                        '"$http_range" "$sent_http_content_range"'; 
     
    #设定请求缓冲    
    client_header_buffer_size 1k;    
    large_client_header_buffers 4 4k; 
     
    #设定access log   
    access_log  logs/access.log  main; 
    client_header_timeout 3m;    
        client_body_timeout 3m;    
        send_timeout 3m;  
 
    sendfile        on; 
    tcp_nopush     on; 
    tcp_nodelay on;   
    #keepalive_timeout  0; 
    keepalive_timeout  65; 
 
    #开启gzip模块  
    gzip  on; 
    gzip_min_length 1100;    
        gzip_buffers 4 8k;    
        gzip_types text/plain application/x-javascript text/css application/xml;   
          
        output_buffers 1 32k;    
        postpone_output 1460; 
     
    server_names_hash_bucket_size 128;   
    client_max_body_size 8m;   
     
    fastcgi_connect_timeout 300;   
    fastcgi_send_timeout 300;   
    fastcgi_read_timeout 300;   
    fastcgi_buffer_size 64k;   
    fastcgi_buffers 4 64k;   
    fastcgi_busy_buffers_size 128k;   
    fastcgi_temp_file_write_size 128k;   
    gzip_http_version 1.1;   
    gzip_comp_level 2;   
    gzip_vary on;

#设定负载均衡的服务器列表    
        upstream localhost {  
            #根据ip计算将请求分配各那个后端tomcat,可以解决session问题
            ip_hash;    
            #同一机器在多网情况下,路由切换,ip可能不同     
            #weigth参数表示权值,权值越高被分配到的几率越大 
        #server localhost:8080 weight=1;    
            #server localhost:9080 weight=1;         
            server 192.168.16.35:8054 max_fails=2 fail_timeout=600s;    
            server 192.168.16.16:8089 max_fails=2 fail_timeout=600s;    
        }  
 
    #设定虚拟主机 
    server {
        listen       80;
        server_name  192.168.16.16;

#charset koi8-r;
    charset UTF-8;
        #设定本虚拟主机的访问日志
        access_log  logs/host.access.log  main;
    #假如访问 /img/*, /js/*, /css/* 资源,则直接取本地文档,不通过squid    
        #假如这些文档较多,不推荐这种方式,因为通过squid的缓存效果更好   
        #location ~ ^/(img|js|css)/ {    
         #           root /data3/Html;    
         #           expires 24h;    
         #       } 
        #对 "/" 启用负载均衡  
        location / {
            root   html; 
            index  index.html index.htm index.aspx; 
             
                        proxy_redirect off;  
                        #保留用户真实信息   
                        proxy_set_header Host $host;    
                        proxy_set_header X-Real-IP $remote_addr;    
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
                        #允许客户端请求的最大单个文件字节数   
                        client_max_body_size 10m;    
                        #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户 
                        client_body_buffer_size 128k;    
                        #跟后端服务器连接超时时间 发起握手等候响应超时时间 
                        proxy_connect_timeout 12; 
                        #连接成功后 等待后端服务器响应时间 其实已进入后端的排队之中等候处理  
                        proxy_read_timeout 90;    
                        #后端服务器数据回传时间 就是在规定时间内后端服务器必须传完所有数据    
                        proxy_send_timeout 90; 
                        #代理请求缓存区 这个缓存区间会保存用户的头信息一共Nginx进行规则处理 一般只要能保存下头信息

即可 
                        proxy_buffer_size 4k;    
                        #同上 告诉Nginx保存单个用的几个Buffer最大用多大空间 
                        proxy_buffers 4 32k;    
                        #如果系统很忙的时候可以申请国内各大的proxy_buffers 官方推荐 *2 
                        proxy_busy_buffers_size 64k;   
                        #proxy 缓存临时文件的大小  
                        proxy_temp_file_write_size 64k;  
                        proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
                        proxy_max_temp_file_size 128m;  
                         
                        proxy_pass http://localhost; 
        }

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    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       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

#    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

# HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

#    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

#    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
四、双击C:\nginx\nginx.exe文件,启动nginx。
五、打开浏览器:
输入http://192.168.16.16 进行访问
测试:关掉S1上的网站,再刷新浏览器访问;关掉S2上的网站,打开S1的网站,刷新浏览器访问。

Nginx+Windows负载均衡(转载)的更多相关文章

  1. nginx windows负载均衡入门

    前言 做了几年开发,都是只管码代码,没有参与过项目的部署,为了知识体系更加完整,于是开始学习一下负载均衡.查了一下资料,觉得用nginx +iis 比较简单,于是小试牛刀. 步骤 准备工作 下载ngi ...

  2. 配置nginx实现windows/iis应用负载均衡(转载)

    配置nginx实现windows/iis应用负载均衡   nginx是俄罗斯人开发的一款跨平台的高性能HTTP和反向代理服务器,可以利用它实现web应用服务器的负载均衡. 反向代理是指将用户请求通过代 ...

  3. windows配置nginx实现负载均衡集群

    windows配置nginx实现负载均衡集群2014-08-20 09:44:40   来源:www.abcde.cn   评论:0 点击:617 网上大部分关于nginx负载均衡集群的教程都是lin ...

  4. windows配置nginx实现负载均衡集群 -请求分流

    windows配置nginx实现负载均衡集群 一.windows上安装nginx 1.下载nginx的windows版本http://nginx.org/en/download.html 2.把压缩文 ...

  5. 转载 深入理解Nginx及使用Nginx实现负载均衡

    转载:https://developer.51cto.com/art/202001/609322.htm 正向代理是代理客户端,也就是客户端能真正接触到的,比如访问外网时需要使用VPN软件,在这个软件 ...

  6. 【转载】Nginx简介及使用Nginx实现负载均衡的原理

    原文地址:http://blog.csdn.net/u014749862/article/details/50522276 是什么? Nginx 这个轻量级.高性能的 web server 主要可以干 ...

  7. Nginx作为负载均衡服务器(Windows环境)

    一个最简单的负载均衡测试,不涉及到session复制,只是将请求分配到不同的服务器上去而已. 1.创建一个简单的web应用.只有一个index.jsp页面,,内容如下. <%@ page lan ...

  8. [转载] nginx的负载均衡

    原文:http://www.srhang.me/blog/2014/08/27/nginx-loabbalance/ Nginx负载均衡 一.特点 1.1 应用情况 Nginx做为一个强大的Web服务 ...

  9. Nginx实现负载均衡 + Keepalived实现Nginx的高可用

    前言 使用集群是大中型网站解决高并发.海量数据问题的常用手段.当一台服务器的处理能力.存储空间不足时,不要企图去换更强大的服务器,对大型网站而言,不管多么强大的服务器,都满足不了网站持续增长的业务需求 ...

随机推荐

  1. 支持向量机通俗导论(理解SVM的三层境界) by v_JULY_v

    支持向量机通俗导论(理解SVM的三层境界) 前言 动笔写这个支持向量机(support vector machine)是费了不少劲和困难的,原因很简单,一者这个东西本身就并不好懂,要深入学习和研究下去 ...

  2. 简单的内存缓存模块 - Smache

    介绍 [sm]art + c[ache] = smache Smache 是一个方便的内存缓存模块,可以通过一些简单缓存策略避免无限占用更多的内存,同时确保最常用最应该被缓存的对象被缓存. GitHu ...

  3. Openshift 3.11和LDAP的集成

    1. OpenLDAP的安装 只记录主要步骤,详细可参考 https://access.redhat.com/solutions/2484371 # yum install -y openldap o ...

  4. LaTeX图片环境 Picture environment

    Picture environment If you need to include simple diagrams or figures in your document, the picture  ...

  5. slf4j log4j logback log4j2关系详解和相关用法

    来源:slf4j log4j logback关系详解和相关用法https://www.cnblogs.com/Sinte-Beuve/p/5758971.html The Simple Logging ...

  6. 使用OctreeQuantizer提高gdi+绘图质量

    .net中gdi+绘制的图形质量很少,原因是gdi+使用的是256色的. 为了提高绘制图片的质量,可以使用是“Octree“ 算法.“Octree“ 算法允许我们插入自己的算法来量子化我们的图像. 一 ...

  7. wkhtmltoimage(网页剪切功能)

    1.wkhtmltoimage使用wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2版本,最新版本为wkhtmltoimage-0.11.0_rc1-stati ...

  8. LeetCode 303 Range Sum Query - Immutable(范围总和查询-永久不变)(*)

    翻译 给定一个整型数组nums,找出在索引i到j(i小于等于j)之间(包含i和j)的全部元素之和. 比如: 给定nums = [-2,0,3,-5,2,-1] sumRange(0, 2) -> ...

  9. POI生成EXCEL文件(字体、样式、单元格合并、计算公式)

    创建一个封装类: package com.jason.excel; import java.io.FileNotFoundException; import java.io.FileOutputStr ...

  10. Android日常开发总结

    全部Activity可继承自BaseActivity,便于统一风格与处理公共事件,构建对话框统一构建器的建立,万一需要整体变动,一处修改到处有效. 数据库表段字段常量和SQL逻辑分离,更清晰,建议使用 ...