1,下载 nginx-1.2.9 2,解压,D:/soft/nginx-1.2.9 3,启动:start nginx,停止:nginx -s stop,重新加载配置:nginx -s reload, 退出:nginx -s quit 4,打开conf下的nginx.conf 第一种,配置配置一台电脑 server { #监听的端口号 listen 80; #ip地址或者主机名字 server_name 192.168.1.35; charset UTF-8; access_log logs/host.access.log main location / { index index.html index.htm; #root D:/soft/nginx-1.2.9/jedis-2.0.0-javadoc; #默认的是nginx安装目录的html目录下的index.html root html; } location ~ ^/ndtracker { #默认的是main.jsp或者index.html或者index.htm index main.jsp index.html index.htm; proxy_pass http://192.168.1.35:8080; }
备注:ndtracker 项目名称
启动jetty或者tomcat服务器,ip地址栏输入http://192.168.1.35/ndtracker即可访问,无需再加端口号8080。
粘贴主要代码第二种负载均衡:
upstream ndtracker {
#weight 参数表示权值,权值越高被分配到的几率越大
server 192.168.1.108:8080 max_fails=3 fail_timeout=60s weight=2;
server 192.168.1.35:8080 max_fails=3 fail_timeout=60s weight=2;
}
server {
#监听的端口号
listen 80;
#ip地址或者主机名字
server_name 192.168.1.35;
charset UTF-8;
access_log logs/host.access.log main;
location / {
index index.html index.htm;
#root D:/soft/nginx-1.2.9/jedis-2.0.0-javadoc;
#默认的是nginx安装目录的html目录下的index.html
root html;
}
location /ndtracker {
#默认的是main.jsp或者index.html或者index.htm
index main.jsp index.html index.htm;
proxy_pass http://ndtracker;
}
负载均衡,代理。