window7 javaweb nginx 反向代理与负载均衡实例运用(附源码与软件安装包)

 本人不罗嗦,不讲理论,不复制解释,直接上运用

 git地址:https://github.com/higherzjm/shareforyou.git

   git资源中包含的部分,nginx 64 免安装,解压直接使用,javawebsimple jdk64

     感兴趣的朋友可以直接从git下载资源,本地安装jdk1.8跟tomcat8即可,复制三份tomcat,端口号按配置分别设为8080、8081、8082,ROOT跟javawebsimple源码复制到webapp下跑起来,反向代理跟负载均衡即可完美彰显

反向代理访问地址:http://www.allenzjm.com/

负载均衡访问地址(静态html):http://www.allenzjm.com/allensite/   刷新游览器每次显示的内容会有变化(负载均地址动态跳转)

负载均衡访问地址(显示图片):http://www.allenzjm.com/allensite/images/myimage.jpg  如上刷新游览器,产生变化

负载均衡访问地址(javaweb项目):http://www.allenzjm.com/allensite/javawebsimple/  如上刷新游览器,产生变化

  如下是nginx.conf(git资源中有)的配置,包括了负载均衡与反向代理的配置,配置中只留下了可实际产生效果的部分,没用的删除了

worker_processes  1;

#打印错误日志路径 
error_log  F:/nginx/nginx-1.14.0/logs/error.log;
error_log  F:/nginx/nginx-1.14.0/logs/notice.log  notice;
error_log  F:/nginx/nginx-1.14.0/logs/info.log  info;
 
pid    F:/nginx/nginx-1.14.0/logs/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
	#配置负载均衡可选服务器 
	#weigth参数表示权值,权值越高被分配到的几率越大
    upstream www.allenzjm.com{
      server 127.0.0.1:8080 weight=1;
      server 127.0.0.1:8081 weight=5;
	  server 127.0.0.1:8082 weight=13;
    }   
 
    server {
        listen       80;
        server_name  www.allenzjm.com;#代理访问路径
		
		#location / {
        #   root   html;
        #   index  index.html index.htm index.jsp;
        #}
 
       
		
		location /allensite/ {
		    # 将所有以http://www.allenzjm.com/allensite/.....请求转发到
			# 负载均衡中的一台服务器
		    proxy_pass http://www.allenzjm.com/; #需要配置成upstream后的负载代理路径一样          
        }
		
	   #配置反向代理
       location / {
           proxy_pass http://localhost:8081; #配置被反向代理的主机路径
		}
		
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
 }
 

运用

猜你喜欢

转载自blog.csdn.net/higherzjm/article/details/82116393