前后端分离nginx配置记录

记录nginx前后端分离部署配置,包含二级目录配置,及API负载均衡配置示例:

# server 地址
upstream app_servers {
    server x.x.x.51:8080;
    server x.x.x.52:8080;
    server x.x.x.53:8080;
}

server {
    listen       9017;
     
    location / {
        root   /home/webapp/project/;
        try_files $uri $uri/ /index.html;
        index index.html;
    }
}

server {
    listen       80;
    server_name www.xxx.com;
    
    location ^~/admin {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	 
        proxy_pass http://127.0.0.1:9017/;
    }

    location ^~/admin/api/ {
        proxy_set_header Host $host;
        # 后台API对接地址
        proxy_pass http://app_servers/api/;
    }
}
展示评论