我正在开发一个自托管.Net Core Rest API,该API将托管在Service Fabric中的Docker容器中。我无法在Service Fabric中配置为SSL / Https。Http似乎有效。我将HttpSys用作Web服务器,而不是Kestrel,因为我将其推荐为没有反向代理(如IIS)的服务的不推荐选项。
这是Web服务器代码段。
return WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.UseHttpSys(
options =>
{
options.Authentication.Schemes = AspNetCore.Server.HttpSys.AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
}
)
.Build();
Run Code Online (Sandbox Code Playgroud)
这是ServiceManifest.xml端点片段。
<Endpoints>
<Endpoint Name="ServiceEndpoint" Protocol="http" Port="80" />
<Endpoint Name="ServiceEndpointHttps" Protocol="https" Port="443" Type="Input" CertificateRef="SSLCertificate" />
</Endpoints>
Run Code Online (Sandbox Code Playgroud)
这是ApplicationManifest EnvironmentVariable片段。
<EnvironmentVariable Name="ASPNETCORE_URLS" Value="https://*:443/;http://*:80/"/>
Run Code Online (Sandbox Code Playgroud)
这是ApplicationManifest.xml策略片段。
<Policies>
<ContainerHostPolicies CodePackageRef="Code">
<RepositoryCredentials AccountName="accountname" Password="password" PasswordEncrypted="false" />
<PortBinding ContainerPort="80" EndpointRef="ServiceEndpoint"/>
<PortBinding ContainerPort="443" EndpointRef="ServiceEndpointHttps"/>
</ContainerHostPolicies>
<EndpointBindingPolicy CertificateRef="SSLCertificate" EndpointRef="ServiceEndpointHttps" />
</Policies>
Run Code Online (Sandbox Code Playgroud)
这是ApplicationManifest.xml证书片段。
<Certificates>
<EndpointCertificate Name="SSLCertificate" X509FindValue="cert thumbprint"/>
</Certificates>
Run Code Online (Sandbox Code Playgroud)
最初,当我仅在CurrentUser \ My证书存储中拥有SSL证书时,我在证书部署方面遇到了问题。在LocalMachine \ My证书存储中部署证书后,我解决了它。使用此修复程序,服务似乎只能在端口80中使用HTTP协议,而不能在端口443中使用HTTPS协议。
Service …