前言前端使用vue.js开发,后端使用tornado框架提供restfulAPI,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/ordershttp://192.168.9.62:9000/v1/ordersnginx配置upstreamsvrs{#Loadbalancingserversserver127.0.0.1:8001;服务器127.0.0.1:8002;服务器127.0.0.1:8003;服务器127.0.0.1:8004;服务器127.0.0.1:8005;服务器127.0.0.1:8006;服务器127.0.0.1:8007;服务器127.0.0.1:8008;服务器127.0.0.1:8009;服务器127.0.0.1:8010;}服务器{听9000;服务器名称_;location/v1{#直接访问http://192.168.9.62:9000/v1/orders配置proxy_pass_headerServer;proxy_redirect关闭;proxy_set_header主机$http_host;proxy_set_headerx-forwarded-for$remote_addr;proxy_set_headerX-Real-IP$remote_addr;proxy_read_timeout120;proxy_passhttp://svrs;}location/api{#访问http://192.168.9.62:9000/api/orders配置#重写api/-->v1/rewrite^.+api/?(.*)$/v1/$1break;#后端API服务器proxy_passhttp://svrs;}location/{#前端打包静态文件root/home/xx/xx_web;索引index.html;}}
