[英]Static files outside the wwwroot for .netcore app
我在我的@home网络服务器上使用https://github.com/ebekker/ACMESharp作为我的SSL(它是免费的!:O)。 这是非常手动的,但在维基上注意到它提到了https://github.com/Lone-Coder/letsencrypt-win-simple上的另一个项目,这是一个用于自动申请,下载和安装SSL的GUI证书到您的网络服务器。
GUI用于验证域的方法是由你自己创建的,随机命名的文件是在[webroot]/.well-known/[randomFile]
内的随机文本字符串,没有扩展名。 使用.dotnetcore应用程序在此[webroot]上运行,即使遵循IIS下更改“处理程序映射”的说明,我也无法提供该文件。
看来我可以通过直接导航到[webRoot]/wwwroot/[whatever]
来提供文件 - 所以为什么我不能在[webroot]/.well-known/[randomFile]
?
有人知道解决这个问题吗? 我可以删除.netcore应用程序,然后运行SSL证书安装,但这个安装需要每2-3个月进行一次,因为它是手动的,我更愿意弄清楚如何以正确的方式做到这一点。
我在这里找到了我需要的信息: https : //docs.asp.net/en/latest/fundamentals/static-files.html
基本上在我的Statup.cs中我需要改变这个:
// allows for the direct browsing of files within the wwwroot folder
app.UseStaticFiles();
// MVC routes
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
对此:
// allows for the direct browsing of files within the wwwroot folder
app.UseStaticFiles();
// Allow static files within the .well-known directory to allow for automatic SSL renewal
app.UseStaticFiles(new StaticFileOptions()
{
ServeUnknownFileTypes = true, // this was needed as IIS would not serve extensionless URLs from the directory without it
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
RequestPath = new PathString("/.well-known")
});
// MVC routes
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
编辑 - 请注意,此目录“.well-known”仅在Web服务器上创建,当我在本地再次开始开发时,我收到错误,因为“.well-known”目录不存在。 所以现在我的项目中只有一个空目录,但至少我的SSL更新是自动化的! :d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.