对于非 PHP / 非静态文件网站,letsencrypt certbot-auto 的 "webroot-path" 应该是什么?

What should letsencrypt certbot-auto's "webroot-path" be for a non-PHP / non-static-files website?

如果您的网站仅使用 Apache(可能使用 PHP),则位于:

/home/www/mywebsite/
/home/www/mywebsite/index.php
/home/www/mywebsite/style.css

那么,设置certbot--webroot-path就很简单了:

./certbot-auto certonly --webroot --webroot-path /home/www/mywebsite/
                        --domain example.com --domain www.example.com --email a@example.com

问题: 使用 NodeJS 网站时 运行 或 Python Flask 或 Bottle,通过 WSGI (mod_wsgi) 或简单代理链接到 Apache(我知道在 Python 的情况下不推荐后者)

RewriteEngine On
RewriteRule /(.*)           http://localhost:5000/ [P,L]

--webroot-path应该是什么?

更具体地说,如果我们有:

/home/www/mywebsite/       (Pyton example)
/home/www/mywebsite/myapp.py
/home/www/mywebsite/myapp.sqlite
/home/www/mywebsite/static/style.css
...

/home/www/mywebsite/        (NodeJS example)
/home/www/mywebsite/myapp.js
/home/www/mywebsite/myapp.sqlite
/home/www/mywebsite/static/style.css
...

那么选择--webroot-path作为/home/www/mywebsite/就没有意义了吧?

事实上,我不希望任何其他 program/script 像 letsencrypt certbot 到 fiddle 我的 .py 文件。

无论如何,certbot 中的 --webroot-path 是做什么的?那里的文件会被分析、解析吗?

非常有趣的问题,但答案却很简单。官方文档指出:

The webroot plugin works by creating a temporary file for each of your requested domains in ${webroot-path}/.well-known/acme-challenge. Then the Let’s Encrypt validation server makes HTTP requests to validate that the DNS for each requested domain resolves to the server running certbot.

因此,对于 Certbot 来说,您的 actual webroot 真正位于何处并不重要,只要它在您尝试为其获取证书的域下提供服务,并且它并不真正感兴趣你的project/framework结构是什么。

换句话说,certbot 不需要访问包含源文件的项目目录。

例如,您服务器上任何应用程序的 Apache 配置都可以共享所谓的 webroot,而 Certbot 只需要 /.well-known/acme-challenge/ 作为静态目录可用,它可以在服务器端存储挑战文件可用于 Certbot 验证服务器:

Alias /.well-known/acme-challenge/ "/var/www/html/.well-known/acme-challenge/"

<Directory "/var/www/html/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

在设置特定服务器块配置时,它对 NGINX 的工作方式相同:

server {

    location /.well-known/acme-challenge/ {
        alias /var/www/html/.well-known/acme-challenge/;
    }

}

如果随后使用以下方式请求证书,则这两个示例都可以使用:

certbot-auto certonly --webroot --webroot-path /var/www/html -d domain.com

这是对 DamagedOrganic 回答的补充信息(完全归功于他)。

为了 certbot / Letsencrypt 验证证书,它必须能够访问 challenge/response URL 像 http://example.com/.well-known/acme-challenge/B39sdfoyoesdf21-qksl2638761867648514.
出于这个原因,它将创建一个临时文件(最后删除,这就是为什么在成功 certbot 后你将不再找到它的原因)例如在 [=16] 给出的路径中名为 .well-known/acme-challenge/B39sdfoyoesdf21-qksl2638761867648514 =]. (然后Letsencrypt的服务器会访问之前提到的URL,以验证是否一切正常。)

解决方案:选择--webroot-path 作为提供静态文件的目录。例子:如果你有这个结构:

/home/www/mywebsite/
/home/www/mywebsite/myapp.py
/home/www/mywebsite/myapp.sqlite
/home/www/mywebsite/static/style.css        # /static/ serves static files... 
/home/www/mywebsite/static/favicon.ico
...

然后使用

./certbot-auto certonly --webroot --webroot-path /home/www/mywebsite/static/
                        --domain example.com --domain www.example.com --email a@example.com

PS: 这是 Bottle 的解决方案(我认为它与 Flask 类似):

@route('/.well-known/acme-challenge/<filename>')
def wellknown(filename):           # Letsencrypt certbot-auto
    return static_file(filename, root='./static/.well-known/acme-challenge')