企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
通过网关访问服务端的默认地址写法如下: ``` url写法:http://zuul-hostname:zuul-port/application-name/要访问的url ``` 这样暴露了集群的真实地址 application-name 不太安全,我们可以在 zuul 模块中做如下优化: *`resources/application.yml`* ```yml server: port: 9528 spring: application: name: cloud-zuul-gateway #默认的访问地址: http://localhost:9528/cloud-payment-service/payment/idport #经过下面层层修改后,最终访问地址为:http://localhost:9528/atguigu/mydept/payment/idport zuul: #访问微服务集群必须添加统一的前缀 atguigu #访问地址更新为:http://localhost:9528/atguigu/cloud-payment-service/payment/idport prefix: /atguigu #禁止使用集群真实的名字进行访问,保证集群安全 #访问地址:http://localhost:9528/cloud-payment-service/payment/idport #cloud-payment-service为微服务集群的真实名字,所以该地址不再有效 #只有少数集群时写成 ignored-services: cloud-payment-service,当有多个集群时写成 "*" 统一禁止使用真实名字访问集群 ignored-services: "*" routes: #需要代理的微服务名,服务端的 spring.application.name 的配置 mydept.serviceId: cloud-payment-service #使用代理名称访问集群,而不是使用真实的地址访问 #访问地址更新为:http://localhost:9528/atguigu/mydept/payment/idport mydept.path: /mydept/** eureka: client: service-url: defaultZone: http://www.eureka7001.com:7001/eureka/ instance: instance-id: ${project.artifactId} prefer-ip-address: true ``` (1)通过网关使用真实地址访问不再有效:http://localhost:9528/cloud-payment-service/payment/idport ```json Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Nov 15 18:30:27 CST 2021 There was an unexpected error (type=Not Found, status=404). No message available ``` (2)使用代理地址访问能够访问:http://localhost:9528/atguigu/mydept/payment/idport ```json instanceId:cloud-provider-payment8001,serverPort:8001 ```