nginx实现vue的web页面项目集群负载

项目场景:

这篇文章仅是记录自己成长路上的愚笨,不喜勿喷,同时也希望各路大神提出优秀的观点。谢谢!!


问题描述:

项目是使用前后端分离,前端使用的是vue技术。
想实现的功能是:在前端项目部署的过程中(直接删除项目目录的文件,然后上传新的项目文件),在这个短时间内不能影响用户的使用。所以想到的就是使用nginx搭建web集群。


nginx配置文件:

    # 页面集群地址
	upstream house_keeper_html {
		server 127.0.0.1:9089;
		server 127.0.0.1:9088;
		ip_hash; # 负载均衡策略
	}
    
    # 页面集群转发
	server {
		listen 9090; # 向外暴露的端口(浏览器直接请求的地址端口)
		location / {
			proxy_pass http://house_keeper_html; #把所有请求转发
		}
	
	}
    
    # 页面集群地址1
    server {
		listen 9089;
		location / {
			root   /home/web_programs/house_keeper/property/back-html5/;
			index  index.html index.html;
			try_files $uri $uri/ /index.html;
			error_page 403 404 @notfound; # 当遇到403或404(项目部署时页面删除的时候)进行转发
		}

		location @notfound {
        		proxy_pass http://127.0.0.1:9088; # 转发的地址
    		 }
	
	}
    
    # 页面集群地址2
    server {
		listen 9088;
		location / {
			root   /home/web_programs/house_keeper/property/back-html5_1/;
			index  index.html index.html;
			try_files $uri $uri/ /index.html;
			error_page 403 404 @notfound; # 同理进行转发
		}

		location @notfound {
     			proxy_pass http://127.0.0.1:9089;
    		 }
	}

思路:

其实就是使用了nginx的错误页面重定向的思路,在其中一台报404的时候nginx检测到后进行转发到另一台。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值