【问题标题】:Azure LetsEncrypt cannot access .well-known/acme-challenge for my functionAzure LetsEncrypt 无法访问我的函数的 .well-known/acme-challenge
【发布时间】:2019-05-28 01:15:01
【问题描述】:

我正在尝试使用 azure 的letsencrypt站点扩展为我的azure函数启用SSL,如here所述。我按照那个 wiki 和这个website 中的说明进行操作。

但是,当它尝试验证网站时出现错误。

错误表示无法访问acme-challenge页面(404)。

这是我在.well-known/下的web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <clear />
      <add name="ACMEStaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
    </handlers>
    <staticContent>
      <remove fileExtension="." />
      <mimeMap fileExtension="." mimeType="text/plain" />
    </staticContent>
  </system.webServer>
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</configuration>

有人对可能出现的问题有任何想法吗?

【问题讨论】:

    标签: azure ssl-certificate azure-functions lets-encrypt


    【解决方案1】:

    您可以这样做。

    在您的函数应用中,为挑战目录创建一个新代理(这是必需的,因为挑战将是对 /.well-known/acme-challenge/ 的 http 访问,并且默认情况下,函数应用中的函数将仅响应 /api/ .

    您可以通过以下方式设置代理。

    proxy.json

    {
      "$schema": "http://json.schemastore.org/proxies",
      "proxies": {
        "LetsEncryptProxy": {
          "matchCondition": {
            "route": "/.well-known/acme-challenge/{code}"
          },
          "backendUri": "http://%WEBSITE_HOSTNAME%/api/letsencrypt/.well-known/acme-challenge/{code}"
        }
      }
    }
    

    这里的重要设置是路由模板:/.well-known/acme-challenge/{*rest} 这将匹配所有进入挑战目录的请求。

    请注意,代理是一项预览功能,您必须启用它才能工作。

    参考: https://github.com/sjkp/letsencrypt-siteextension/wiki/Azure-Functions-Support https://blog.bitscry.com/2018/07/06/using-lets-encrypt-ssl-certificates-with-azure-functions/

    【讨论】:

    • 感谢您的回复。我创建了代理,但仍然收到错误 404,如下所示:acme-staging.api.letsencrypt.org/acme/authz/…。我按照在您的链接中创建代理的说明进行操作,并且还添加了该链接中描述的 azure 功能。有什么建议么?再次感谢
    【解决方案2】:

    我想通了:

    类似于 KetanChawda-MSFT 的回答,除了代理需要访问您创建的 api 端点函数。

    函数如下:

    // https://YOURWEBSITE.azurewebsites.net/api/letsencrypt/{code}
    
    #r "Newtonsoft.Json"
    
    using System.Net;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Primitives;
    using Newtonsoft.Json;
    
    public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string code, TraceWriter log)
    {    
        log.Info($"C# HTTP trigger function processed a request. {code}");
    
        var content = File.ReadAllText(@"D:\home\site\wwwroot\.well-known\acme-challenge\"+code);
        var resp = new HttpResponseMessage(HttpStatusCode.OK);
        resp.Content =  new StringContent(content, System.Text.Encoding.UTF8, "text/plain");
        return resp;
    }
    

    当letsEncrypt 尝试验证acme 质询时,这是触发该功能的代理:

    {
      "$schema": "http://json.schemastore.org/proxies",
      "proxies": {
        "LetsEncryptProxy": {
          "matchCondition": {
            "route": "/.well-known/acme-challenge/{code}"
          },
          "backendUri": "http://%WEBSITE_HOSTNAME%/api/letsencrypt/{code}"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 2018-11-09
      • 2019-01-04
      • 2021-07-25
      • 2016-04-08
      • 2019-04-05
      • 2018-02-25
      • 1970-01-01
      • 2020-08-30
      相关资源
      最近更新 更多