ASP.Net 应用程序干扰远程主机 Let's Encrypt(通过 Plesk)安装?

ASP.Net application interfering with remote host Let's Encrypt (via Plesk) installation?

所以,要安装 Let's Encrypt SSL 证书,我转到我的 Plesk 帐户,选择一个域或子域并单击 Let's Encrypt 然后我只有一个字段可以输入电子邮件地址,还有一个按钮可以安装.

要安装,Let's Encrypt 会向我的网站发送一个 HTTP 请求:

GET /.well-known/acme-challenge/n9cD8Lpv-woEU73NhCUdFyqOYMc5hrANF_byoiaYrZc - HTTP/1.1

如果我通过 Plesk 创建一个新的 'site',并安装证书,GET 请求会得到一个很好的 200 响应,并且 SSL 证书安装正常。

但是,我有一个未安装 SSL 的 'sandbox',然后我将一个 ASP.NetCore 应用程序部署到 'sandbox' 以进行暂存,然后尝试安装 SSL 证书。对于 ASP.NetCore 应用程序 运行ning,当 Let's Encrypt 发送该 GET 请求时,它会导致 404 错误并且安装失败。

有人 运行 参与其中吗?我需要配置什么?是 MVC 路由还是干扰的 AngularJS (~1.5) 路由?

我在任何地方都没有看到 /.well-known/* 目录,我不确定它是否被隐藏,但我无法访问它,所以我怎么知道要配置什么,如果我需要在路由中配置一些东西以允许 GET /.well-known/acme-challenge/*?

远程主机技术支持没有帮助。他们让我等 72 小时,因为我尝试了很多次,但我只是被锁在门外(我没有)

这是实际的 Plesk 错误消息

Let's Encrypt SSL certificate installation failed: Challenge marked as invalid. Details: Invalid response from http://my-domain.net/.well-known/acme-challenge/AJsMc3HXiOZRGaFVsMR3uZEdYu1moJ2Po62t3e6uV10 [my-ip]: 404

我相当确定我可以 'work around' 通过删除我的网站、安装 SSL 证书而不是再次上传来做到这一点,但我想知道实际发生了什么,以及我是否可以处理它适当地。

事后思考

Let's Encrypt 是一项 30 天的自动续订服务。如果我的 ASP.NET 应用程序阻止安装,那么它也会阻止自动续订,所以我必须每 30 天删除我的站点并重新部署,不能接受!

已解决 这是这个非常具体的场景的解决方案。

还有其他可行的变通方法,当然,此解决方案仅适用于 IIS Web 服务器。

快速搜索得到了这个 gem

Using Let’s encrypt with ASP.NET Core

这似乎符合您的特定问题。

To get a certificate, let’s encrypt verify that you own the domain by requesting a file on your server. In this case, the file is not accessible (status 404). Let’s understand what happened.

IIS get the request, and find the associated web site. Then it executes handlers in order until one send the response. ASP.NET Core handler is the first to handle the request.

The challenge file is in the folder “.well-known/…”, but by default ASP.NET Core serves only files located in the folder “wwwroot” => so, a 404 response is send to the client. ASP.NET Core has handled the request; therefore, the IIS Static file handler is not called.

As a workaround, you can move up the “StaticFile” handler, but your website may not work as expected. A better solution is to instruct your ASP.NET Core website to send the file located in the directory “.well-known”.

This is possible by registering it:

public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
    //...other configs

    app.UseStaticFiles(); // wwwroot
    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
        RequestPath = new PathString("/.well-known"),
        ServeUnknownFileTypes = true // serve extensionless file
    });

    //...other configs

    app.UseMvc();
}

这基本上通过核心路由对虚拟路径的调用,核心获取物理路径并将文件内容提供给调用者。现在应该可以验证域并让证书请求流程完成并自动续订。

查看这篇文章及其建议的解决方法,因为似乎没有涉及太多额外的步骤。