首页 > 其他 > 详细

nginx location配置前后端地址

时间:2021-07-02 15:15:30      阅读:12      评论:0      收藏:0      [点我收藏+]

location 后面地址的说明

location /api/esbapi nginx 会对前端访问的地址进行截取,例如前端访问地址是 http://localhost:4800/api/esbapi/manager/cm0004 那么截取后 剩余的地址为 /manager/cm0004
,然后再加上 proxy_pass= http://127.0.0.1:56668/esbapi 代理的后端地址后,实际访问的地址为 http://127.0.0.1:56668/esbapi/manager/cm0004

fontEndUrl=http://localhost:4800/api/esbapi/manager/cm0004

split_address=fontEndUrl - /api/esbapi
             = /manager/cm0004

backEndUrl= http://127.0.0.1:56668/esbapi

realPath= backEndUrl + split_address
        = http://127.0.0.1:56668/esbapi/manager/cm0004

配置文件实例

server{
		listen 4800; # 配置端口
		server_name localhost; # 配置域名
		charset utf-8; # 编码
		access_log C:/Users/Administrator/Desktop/nginx-1.12.2/logs/access.log main; # 成功日志
		error_log C:/Users/Administrator/Desktop/nginx-1.12.2/logs/error.log error; # 错误日志
		index index.html; # 查找文件顺序
		# 其余location
		#静态资源访问
		location / {
            #------------------前台资源跟路径------------------
            root   C:/Users/Administrator/Desktop/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

		location /api {
			proxy_pass http://127.0.0.1:56668;
		}
		
		#/api/esbapi 对前端请求的匹配和地址截取
		#http://localhost:4800/api/esbapi/manager/cm0004 截取后保留 /manager/cm0004
		#然后定位到后端地址 /esbapi/manager/cm0004 其中esbapi是后端的 context-path
		location /api/esbapi {
			proxy_pass http://127.0.0.1:56668/esbapi;
		}
		
		location /api/mqcore {
			proxy_pass http://127.0.0.1:56666/mqcore;
		}
		
		location /api/mqtask {
			proxy_pass http://127.0.0.1:56669/mqtask;
		}
	}

nginx location配置前后端地址

原文:https://www.cnblogs.com/iullor/p/14962625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!