zoukankan      html  css  js  c++  java
  • nginx location配置前后端地址

    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;
    		}
    	}
    
  • 相关阅读:
    【每天一道PAT】1001 A+B Format
    C++ STL总结
    开篇
    happen-before原则
    java多线程的状态转换以及基本操作
    集合初始容量
    fail-fast机制
    Stack
    Iterator
    Vector
  • 原文地址:https://www.cnblogs.com/iullor/p/14962625.html
Copyright © 2011-2022 走看看