Ocelot对Consul进行配置,通过Ocelot访问502错误问题

  • A+
所属分类:.NET技术
摘要

在Ocelot中配置好Consul之后.在浏览器中查看,返回502错误.控制台给出的错误信息:
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
requestId: 0HMBJ7BTDT1K6:00000006, previousRequestId: no previous request id, message:
Error Code: ConnectionToDownstreamServiceError Message: Error connecting to downstream service
, exception: System.Net.Http.HttpRequestException: 不知道这样的主机。

在Ocelot中配置好Consul之后.

在浏览器中查看,返回502错误.

控制台给出的错误信息:
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
requestId: 0HMBJ7BTDT1K6:00000006, previousRequestId: no previous request id, message:
Error Code: ConnectionToDownstreamServiceError Message: Error connecting to downstream service
, exception: System.Net.Http.HttpRequestException: 不知道这样的主机。

 

解决方法:
成因:造成这的问题是,consul支持SSL认证加入的处理。如果有node,下游地址使用node.name.
解决方法:
第一种:在启动consul的时候,node参数可以写成 -node=127.0.0.1
如:consul agent -server -ui -bootstrap-expect=1 -data-dir=d:consul -node=127.0.0.1 -client=0.0.0.0 -bind=127.0.0.1 -datacenter=dc1 -join 127.0.0.1

第二种:在启动consul的时候,node参数可写成"hostname",在Hosts文件中对,node参数添加dns解析.
consul agent -server -ui -bootstrap-expect=1 -data-dir=d:consul -node=hostname -client=0.0.0.0 -bind=127.0.0.1 -datacenter=dc1 -join 127.0.0.1
win7 hosts文件位置:C:WindowsSystem32driversetc

在hosts文件中添加一行"127.0.0.1 hostname",即可

Ocelot对Consul进行配置,通过Ocelot访问502错误问题