首页 新闻 赞助 找找看

使用ocelot做的api gateway本地测试是ok的,发布到iis中就出问题了

0
悬赏园豆:20 [已解决问题] 解决于 2019-06-10 12:30

Ocelot版本2.0.0

在本地测试

api.geteway网址是http://localhost:62082

api.log网址是http://localhost:59991

这样配置的api geteway

{
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"DownstreamHost": "localhost",
"DownstreamPort": 59991,
"UpstreamPathTemplate": "/log/{url}",
"UpstreamHttpMethod": [ "Get", "Post" ]
},

测试链接请求

 

通过vs发布后将文件上传到iis服务器(在一个服务器上),AspNetCoreModule和AspNetCoreModuleV2模块是有的,发布的api.gateway网站和api.log网站都是无托管代码,

服务器版本:Windows Server 2012 R2 数据中心版 64位中文版

api.geteway网址是http://apigateway.test.ylsdai.com

api.log网址是http://apilog.test.ylsdai.com

 

在api.log中添加了跨域《https://www.cnblogs.com/dotnet261010/p/10177166.html

在StartUp类的ConfigureServices方法中添加如下代码:

// 配置跨域处理,允许所有来源
services.AddCors(options =>
options.AddPolicy("cors",
p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials()));
修改Configure方法

// 允许所有跨域,cors是在ConfigureServices方法中配置的跨域策略名称
app.UseCors("cors");

也还是不行

 

 

这个是对应的配置信息

{
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"DownstreamHost": "apilog.test.ylsdai.com",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/log/{url}",
"UpstreamHttpMethod": [ "Get", "Post" ]
},

直接访问api.log是ok的

 

通过api.gateway转发不可以访问

 

api.gateway日志记录:

复制代码
info: CacheManager.Core.BaseCacheManager[0]
      Cache manager: adding cache handles...
info: CacheReflectionHelper[0]
      Creating handle 96a7975d3daa482fbd38eff4113653eb of type CacheManager.Core.Internal.DictionaryCacheHandle`1[TCacheValue].
info: CacheManager.Core.BaseCacheManager[0]
      Cache manager: adding cache handles...
info: CacheReflectionHelper[0]
      Creating handle 50ae221020ab4e2d8a667b7e988d4271 of type CacheManager.Core.Internal.DictionaryCacheHandle`1[TCacheValue].
warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
      Using an in-memory repository. Keys will not be persisted to storage.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
      Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver[53]
      Repository contains no viable default key. Caller should generate a key with immediate activation.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[57]
      Policy resolution states that a new key should be added to the key ring.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
      Creating key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} with creation date 2019-05-29 01:44:34Z, activation date 2019-05-29 01:44:34Z, and expiration date 2019-08-27 01:44:34Z.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[32]
      Descriptor deserializer type for key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} is 'Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[34]
      No key escrow sink found. Not writing key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} to escrow.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} may be persisted to storage in unencrypted form.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[23]
      Key cache expiration token triggered by 'CreateNewKey' operation.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[18]
      Found key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48}.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver[13]
      Considering key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} with expiration date 2019-08-27 01:44:34Z as default key.
dbug: Microsoft.AspNetCore.DataProtection.TypeForwardingActivator[0]
      Forwarded activator type request from Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 to Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Culture=neutral, PublicKeyToken=adb9793829ddae60
dbug: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.CngCbcAuthenticatedEncryptorFactory[4]
      Opening CNG algorithm 'AES' from provider '(null)' with chaining mode CBC.
dbug: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.CngCbcAuthenticatedEncryptorFactory[3]
      Opening CNG algorithm 'SHA256' from provider '(null)' with HMAC.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[2]
      Using key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} as the default key.
dbug: Microsoft.AspNetCore.DataProtection.Internal.DataProtectionStartupFilter[0]
      Key ring with default key {99a3cc42-54f8-49e7-97fb-5b0f91e3bd48} was loaded during application startup.
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[3]
      Hosting starting
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[4]
      Hosting started
Hosting environment: Production
Content root path: D:\web\MSA\Api\Api.Gateway
Now listening on: http://localhost:23577
Application started. Press Ctrl+C to shut down.
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[0]
      Loaded hosting startup assembly Api.Gateway
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[0]
      Loaded hosting startup assembly Microsoft.AspNetCore.Server.IISIntegration
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HLN3QSQ5C8R4" started.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://apigateway.test.ylsdai.com/  
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
      Connection id "0HLN3QSQ5C8R4" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 94.3615ms 404 
dbug: CacheManager.Core.Internal.DictionaryCacheHandle[0]
      '50ae221020ab4e2d8a667b7e988d4271' starting eviction scan.
dbug: CacheManager.Core.Internal.DictionaryCacheHandle[0]
      '96a7975d3daa482fbd38eff4113653eb' starting eviction scan.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://apigateway.test.ylsdai.com/log/agent/index  
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
      Connection id "0HLN3QSQ5C8R4" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 0.5847ms 404 
dbug: CacheManager.Core.Internal.DictionaryCacheHandle[0]
      '50ae221020ab4e2d8a667b7e988d4271' starting eviction scan.
dbug: CacheManager.Core.Internal.DictionaryCacheHandle[0]
      '96a7975d3daa482fbd38eff4113653eb' starting eviction scan.
dbug: CacheManager.Core.Internal.DictionaryCacheHandle[0]
      '50ae221020ab4e2d8a667b7e988d4271' starting eviction scan.
 
 
 
 
复制代码
spatxos的主页 spatxos | 初学一级 | 园豆:32
提问于:2019-05-29 10:25
< >
分享
最佳答案
0

Ocelot版本2.0.0 这版本老了吧,用最新版本,参看官方文档 ,也可以从我整理的文档集合开始 https://github.com/geffzhang/awesome-ocelot

收获园豆:20
张善友 | 小虾三级 |园豆:557 | 2019-06-06 22:03
其他回答(1)
0

已经找到解决方案,将ocelot和.net core升级到最新版时,提示Unable to start Ocelot, errors are: ,Downstream Path Template {url} doesnt start with forward slash ,因为在其他的转发配置中

{
"DownstreamPathTemplate": "{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "apistatic.test.ylsdai.com",
"Port": 80
}
],
"UpstreamPathTemplate": "/static/{url}",
"UpstreamHttpMethod": [ "Get", "Post" ]
}

 

 

"DownstreamPathTemplate": "{url}",这一句有问题,应该是"DownstreamPathTemplate": "/{url}",
但是在低版本中本地不会报错(哔了狗),到生产环境就报错了,但是这时的日志不好记录,一直以为是转发的问题

spatxos | 园豆:32 (初学一级) | 2019-06-06 18:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册