在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:\Windows\System32\drivers\etc
在hosts文件中添加一行"127.0.0.1 hostname",即可

