1.设置nginx 传递头信息
#配置api.leyou.com访问网关
server {
listen 80;
server_name api.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Hsot $host;
#上传路径映射 api.leyou.com/api/upload/image
location /api/upload {
proxy_pass http://127.0.0.1:8082;
#路径重写 重写后去掉api前缀 http://127.0.0.1:8082:upload/image
rewrite "^/api/(.*)$" /$1 break;
}
location / {
proxy_pass http://127.0.0.1:10010;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
2. 修改网关配置文件
zuul:
sensitive-headers: #全部服务忽略敏感头(全部服务都可以传递cookie)
add-host-header: true
prefix: /api
routes:
item-service: /item/** #路由到商品微服务
search-service: /search/** #路由到搜索微服务
user-service: /user/** #用户微服务
auth-service: /auth/** #认证微服务