[英]Asp.net core SSL could not run in docker container
I have Startup.cs 我有Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
var options = new RewriteOptions().AddRedirectToHttps(301, 44339);
app.UseRewriter(options);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
var localizedOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(localizedOptions.Value);
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
"LocalizedDefault",
"{lang:lang}/{controller=Home}/{action=Index}/{id?}"
);
routes.MapRoute(
"default",
"{*catchall}",
new { controller = "Home", action = "RedirectToDefaultLanguage", lang = "vi" });
});
}
and 和
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel().UseUrls("https://*:443")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
I used this cmd: 我用过这个cmd:
docker run -it --rm -p 1234:80 --name voiconshop_ps voiconshop
Here is ps: 这是ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f752d350823b voiconshop "dotnet VoiConShop.d…" About a minute ago Up 59 seconds 0.0.0.0:1234->80/tcp voiconshop_ps
And this is dockerfile 这是dockerfile
FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "VoiConShop.dll"]
I run http://localhost:1234/ then direct to https://localhost:44339/ . 我运行http:// localhost:1234 /然后直接到https:// localhost:44339 / 。 However, the page return "This site can't be reached".
但是,页面返回“无法访问此站点”。 So what did I do wrongly?
那我做错了什么? Please help me.
请帮我。 Thanks you so much.
非常感谢。 If need more information I will edit this question.
如果需要更多信息,我会编辑这个问题。
I see multiple issues in your implementation. 我在您的实现中看到了多个问题。
I think running web app/service in HTTPs requires SSL certificate to be bound. 我认为在HTTP中运行Web应用程序/服务需要绑定SSL证书。 Consider the below code snippet to replace .UseKestrel() in your code.
请考虑以下代码片段,以替换代码中的.UseKestrel()。 Implement LoadCertificate method to return your SSL Certificate(X509Certificate2 object)
实现LoadCertificate方法以返回您的SSL证书(X509Certificate2对象)
.UseKestrel((options => { options.Listen(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 443), listenOptions => { var certificate = LoadCertificate(); var httpsConnectionAdapterOptions = new AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions() { ClientCertificateMode = AspNetCore.Server.Kestrel.Https.ClientCertificateMode.NoCertificate, SslProtocols = System.Security.Authentication.SslProtocols.Tls, ServerCertificate = certificate }; listenOptions.UseHttps(httpsConnectionAdapterOptions); });
Add 443 port in dockerfile. 在dockerfile中添加443端口。 It should look like
应该是这样的
Expose 80 443 暴露80 443
We should also set "ASPNETCORE_URLS" Envionment Variable with "http:// :80/;https:// :443/" in docker-compose.override.yml. 我们还应该在docker-compose.override.yml中使用“http:// :80 /; https:// :443 /”设置“ASPNETCORE_URLS”Envionment Variable。
environment: 环境:
ports: 端口:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.