利用Spring Cloud Gateway隐藏微服务及API安全访问
1. 使用Spring Cloud Gateway隐藏微服务
Spring Cloud Gateway可作为边缘服务器,灵活控制外部对系统内服务的访问。下面介绍如何配置和测试相关路由规则。
1.1 路由配置
为使对其他主机名的调用返回501未实现错误,可设置如下路由:
- id: host_route_501
uri: http://httpstat.us
predicates:
- Path=/headerrouting/**
filters:
- SetPath=/501
1.2 测试边缘服务器
测试边缘服务器需按以下步骤操作:
1. 构建Docker镜像:
cd $BOOK_HOME/Chapter10
./gradlew clean build && docker-compose build
- 启动系统并运行测试:
./test-em-all.bash start
- 期望输出与之前章节类似。
- 从日志输出中,注意倒数第二个测试结果
http://localhost:8080
超级会员免费看
订阅专栏 解锁全文
168万+

被折叠的 条评论
为什么被折叠?



