nginx实现vue和后端的双机负载

nginx配置文件,项目是前后端分离的,前端vue,后端springboot
前端使用nginx实现双机负载,前端的访问端口是95280,后端2个服务实例的端口分部为9098,9099

nginx.conf的配置文件

#user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
 
    keepalive_timeout  65;
         
    #这里是配置负载均衡
    upstream xx_front {
        server 127.0.0.1:9098;
		server 127.0.0.1:9099;
    }              
    server {
        listen       9528;
        server_name  xx.xx.xx.xx;
 
        location / {
            root   xx/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
       #配置由前端路由到后端
        location /data-management/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xx_front;
        }
    }
}

你可能感兴趣的:(nginx,vue.js,运维,双机负载,负载均衡)