vue代理模式 nginx配置
前言
前端使用vue.js开发,后端使用tornado框架提供restful API, vue.js使用代理;如 当前端js请求http://192.168.9.62:9000/api/orders时候后端通过nginx配置去请求http://192.168.9.62:9000/v1/orders
需求
nginx需要将前端js请求http://192.168.9.62:9000/api/orders 转发 http://192.168.9.62:9000/v1/orders
nginx配置
upstream svrs { # 负载均衡的servers server 127.0.0.1:8001; server 127.0.0.1:8002; server 127.0.0.1:8003; server 127.0.0.1:8004; server 127.0.0.1:8005; server 127.0.0.1:8006; server 127.0.0.1:8007; server 127.0.0.1:8008; server 127.0.0.1:8009; server 127.0.0.1:8010; } server { listen 9000; server_name _; location /v1 { # 直接访问 http://192.168.9.62:9000/v1/orders 的配置 proxy_pass_header Server; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header x-forwarded-for $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 120; proxy_pass http://svrs; } location /api { # 访问http://192.168.9.62:9000/api/orders 的配置 # 重写 api/ --> v1/ rewrite ^.+api/?(.*)$ /v1/$1 break; # 后端的API服务器 proxy_pass http://svrs; } location / { # 前端打包的静态文件 root /home/xx/xx_web; index index.html; } }
相关推荐
Luckyunyun 2020-08-15
yuzhu 2020-11-16
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
sjcheck 2020-11-03
怪我瞎 2020-10-28
源码zanqunet 2020-10-28
gloria0 2020-10-26
王军强 2020-10-21
学习web前端 2020-09-28
QiaoranC 2020-09-25
anchongnanzi 2020-09-21
安卓猴 2020-09-12
Macuroon 2020-09-11
kiven 2020-09-11
LittleCoder 2020-09-11
Cheetahcubs 2020-09-13
小焊猪web前端 2020-09-10