首页新闻找找看学习计划

关于asp.net core打包到docker,然后设置成https

0
悬赏园豆:20 [待解决问题]

大佬们,求指教,谢了。

asp.net core

return WebHost.CreateDefaultBuilder(args)
                //.UseUrls("https://*:5001")
                .UseStartup<Startup>()
                .ConfigureKestrel(options => 
                {
                    options.Listen(IPAddress.Loopback, 5001, listenOptions =>
                    {
                        listenOptions.UseHttps("server.pfx", "linezero");
                    });
                })
                .Build();

dockerfile

FROM mcr.microsoft.com/dotnet/core/runtime:2.2 AS base
WORKDIR /safety_experience_hall
EXPOSE 5001

FROM base AS final
WORKDIR /safety_experience_hall
COPY . /safety_experience_hall
ENV ASPNETCORE_ENVIRONMENT Production
ENTRYPOINT ["dotnet", "Qianbian.SafetyExperienceHall.Web.Host.dll"]

容器

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                     NAMES
5c04e916d71d        safety_experience_hall:v7   "dotnet Qianbian.Saf…"   13 seconds ago      Up 12 seconds              0.0.0.0:9595->5001/tcp    goofy_snyder

运行结果

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
      Creating key {dba781f4-67f0-45ec-b28f-c0619369ee8b} with creation date 2019-08-15 03:52:58Z, activation date 2019-08-15 03:52:58Z, and expiration date 2019-11-13 03:52:58Z.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {dba781f4-67f0-45ec-b28f-c0619369ee8b} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
      Writing data to file '/root/.aspnet/DataProtection-Keys/key-dba781f4-67f0-45ec-b28f-c0619369ee8b.xml'.
      warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Overriding address(es) 'http://+:80'. Binding to endpoints defined in UseKestrel() instead.
Hosting environment: Production
Content root path: /safety_experience_hall
Now listening on: https://127.0.0.1:5001
Application started. Press Ctrl+C to shut down.
骑着蚊子去太阳的主页 骑着蚊子去太阳 | 初学一级 | 园豆:160
提问于:2019-08-15 12:04
< >
分享
所有回答(2)
0

这不挺好的么,没问题呀。

czd890 | 园豆:7028 (大侠五级) | 2019-08-15 12:47

大佬,我访问

https://127.0.0.1:5001

直接就是拒绝访问了。不知道还要配置啥,
9595这个端口也访问不了

支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 12:57

@骑着蚊子去太阳: 是拒绝访问,还是端口不通?

支持(0) 反对(0) czd890 | 园豆:7028 (大侠五级) | 2019-08-15 13:34

@czd890:

windows 10 ,docker 也是在windows 10 上的

  • 在浏览器直接输入https://127.0.0.1:5001,显示127.0.0.1 已拒绝连接。ERR_CONNECTION_REFUSED,然后telnet 127.0.0.1 5001,连接失败
  • 在浏览器输入http://127.0.0.1:9595 ,显示的是127.0.0.1 未发送任何数据。ERR_EMPTY_RESPONSE,然后telnet 127.0.0.1 9595,能通
  • netstat -aon|findstr "9595"
TCP    0.0.0.0:9595           0.0.0.0:0              LISTENING       15640
  TCP    127.0.0.1:9595         127.0.0.1:61197        TIME_WAIT       0
  TCP    [::]:9595              [::]:0                 LISTENING       15640
支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 14:25

@czd890: 不整成https是可以的

支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 14:39

@骑着蚊子去太阳:
127.0.0.1:5001 是你docker container的地址 端口不通是对的
127.0.0.1:9595 是你host主机的地址。端口通是对的

程序 log级别设置到trace,看看日志

你可以想在本机以console run 起来你的程序,看看走https是不是ok,在放到docker里面是不是ok

支持(0) 反对(0) czd890 | 园豆:7028 (大侠五级) | 2019-08-15 17:22

@czd890: 大佬,本地测试可以的,发布到docker没有啥日志输出啊。

支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 18:32

@czd890: 大佬,我真看不出来。

dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[3]
      Hosting starting
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
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 {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} with creation date 2019-08-15 10:38:48Z, activation date 2019-08-15 10:38:48Z, and expiration date 2019-11-13 10:38:48Z.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[32]
      Descriptor deserializer type for key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} 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 {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} to escrow.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
      Writing data to file '/root/.aspnet/DataProtection-Keys/key-8deab1a7-af73-43bc-93f5-5712ffa4e1c3.xml'.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[23]
      Key cache expiration token triggered by 'CreateNewKey' operation.
dbug: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[37]
      Reading data from file '/root/.aspnet/DataProtection-Keys/key-8deab1a7-af73-43bc-93f5-5712ffa4e1c3.xml'.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[18]
      Found key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3}.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver[13]
      Considering key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} with expiration date 2019-11-13 10:38:48Z 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.ManagedAuthenticatedEncryptorFactory[11]
      Using managed symmetric algorithm 'System.Security.Cryptography.Aes'.
dbug: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ManagedAuthenticatedEncryptorFactory[10]
      Using managed keyed hash algorithm 'System.Security.Cryptography.HMACSHA256'.
dbug: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[2]
      Using key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} as the default key.
dbug: Microsoft.AspNetCore.DataProtection.Internal.DataProtectionStartupFilter[0]
      Key ring with default key {8deab1a7-af73-43bc-93f5-5712ffa4e1c3} was loaded during application startup.
dbug: Microsoft.AspNetCore.Mvc.MvcJsonOptions[0]
      Compatibility switch AllowInputFormatterExceptionMessages in type MvcJsonOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch AllowCombiningAuthorizeFilters in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch AllowBindingHeaderValuesToNonStringModelTypes in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch AllowValidatingTopLevelNodes in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch InputFormatterExceptionPolicy in type MvcOptions is using compatibility value MalformedInputExceptions for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch SuppressBindingUndefinedValueToEnumType in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch EnableEndpointRouting in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch MaxValidationDepth in type MvcOptions is using compatibility value 32 for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcOptions[0]
      Compatibility switch AllowShortCircuitingValidationWhenNoValidatorsArePresent in type MvcOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.ApiBehaviorOptions[0]
      Compatibility switch SuppressMapClientErrors in type ApiBehaviorOptions is using default value False
dbug: Microsoft.AspNetCore.Mvc.ApiBehaviorOptions[0]
      Compatibility switch SuppressUseValidationProblemDetailsForInvalidModelStateResponses in type ApiBehaviorOptions is using default value False
dbug: Microsoft.AspNetCore.Mvc.ApiBehaviorOptions[0]
      Compatibility switch AllowInferringBindingSourceForCollectionTypesAsFromQuery in type ApiBehaviorOptions is using default value False
dbug: Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions[0]
      Compatibility switch AllowAreas in type RazorPagesOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions[0]
      Compatibility switch AllowMappingHeadRequestsToGetHandler in type RazorPagesOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions[0]
      Compatibility switch AllowDefaultHandlingForOptionsRequests in type RazorPagesOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions[0]
      Compatibility switch AllowRecompilingViewsOnFileChange in type RazorViewEngineOptions is using default value False
dbug: Microsoft.AspNetCore.Mvc.MvcViewOptions[0]
      Compatibility switch SuppressTempDataAttributePrefix in type MvcViewOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.MvcViewOptions[0]
      Compatibility switch AllowRenderingMaxLengthAttribute in type MvcViewOptions is using compatibility value True for version Version_2_2
dbug: Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory[12]
      Registered model binder providers, in the following order: Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ServicesModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.HeaderModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FloatingPointTypeModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.EnumTypeModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.SimpleTypeModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.CancellationTokenModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ByteArrayModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FormFileModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FormCollectionModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.KeyValuePairModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.DictionaryModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ArrayModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.CollectionModelBinderProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinderProvider
dbug: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[2]
      Failed to locate the development https certificate at '(null)'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Overriding address(es) 'https://*:5001'. Binding to endpoints defined in UseKestrel() instead.
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[4]
      Hosting started
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[0]
      Loaded hosting startup assembly HttpsDemo
Hosting environment: Production
Content root path: /app
Now listening on: https://127.0.0.1:5001
Application started. Press Ctrl+C to shut down.
支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 18:40

@czd890: 证书问题?我证书是随便在网上下的一个

支持(0) 反对(0) 骑着蚊子去太阳 | 园豆:160 (初学一级) | 2019-08-15 18:41
0

你访问的IP错了,不是127.0.0.1,应该是192.168.99.100:9595

ch00486259 | 园豆:202 (菜鸟二级) | 2019-10-11 11:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册