我有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" });
});
}
和
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel().UseUrls("https://*:443")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
我用这个命令:
docker run -it --rm -p 1234:80 --name voiconshop_ps voiconshop
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
这是dockerfile
FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "VoiConShop.dll"]
我运行http://localhost:1234/,然后直接指向https://localhost:44339/。但是,页面返回“无法访问此站点”。
那我做错了什么?
请帮我。非常感谢。
如果需要更多信息,我将编辑此问题。
最佳答案
在您的实施中,我看到了多个问题。
.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);
});
暴露80443
环境:
端口:
关于asp.net-core - ASP.NET Core SSL无法在Docker容器中运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49757169/