日期:2014-05-17  浏览次数:21161 次

Windows下实现Nginx+Tomcat集群部署方案

? ? ? ? ? Nginx 作为一款非常优秀的 Http 服务器,绝对属于后起之秀中的佼佼者,它在能够支持高达 50000 个并发连接数的响应,强大的静态资源处理能力,并且运行稳定、内存、 CPU 等系统资源消耗非常低,比起庞大而臃肿的 Apache 有着非常明显的优势。目前,国内很多较大的互联网公司都在使用 Nginx 作为前端的 Http 应用服务器,如:新浪、腾讯等。本文的主要内容是讲解以 Nginx 作为负载均衡器、 Tomcat 作为应用服务器的负载集群的设置方法。

???????? 环境: windows 7 专业版 + nginx-1.1.5 + apache-tomcat-7.0.20-windows-x86 nginx-1.1.5 http://nginx.org/en/download.html 下载。

?????? 配置 Tomcat

???????? 1 )拷贝两个 Tomcat tomcat1 tomcat2 ,端口分别为 8080 8081

???????? 2 Tomcat server.xml 的配置方式与 <<Linux 下实现 Apache+Tomcat 集群负载均衡 >> 的配置方式一模一样。

???????? 配置 Nginx

???????? 1 )打开 Nginx 的配置文件,位置: nginx-1.1.5\conf\nginx.conf

???????? 2 )在 http {…} - server{…} - location / {…} 中加入一行:“ proxy_pass http://127.0.0.1 ; ”如下:

???????????? location / {

??????????? ???? root?? html;

??????????????? index? index.html index.htm;

???????? ??????? proxy_pass??? http://127.0.0.1;

? ? ? ? ? ?? }

???????? 3 )在 http {…} 中加入以下代码:

# 设定负载均衡的服务器列表

??? ???????? upstream 127.0.0.1 {

??????? ???????? #weigth 参数表示权值,权值越高被分配到的几率越大

??????? ???????? server 127.0.0.1:8080 weight=1;