nginx server_name 正则表达式捕获未在 ssl_certificate 中被替换

nginx server_name regex capture not getting substituted in ssl_certificate

我正在尝试以下操作:

server_name ~^domain\.(?<tld>.*)$;
ssl_certificate /etc/ssl/private/ssl-chain-domain-$tld.pem;

我得到:

[emerg] 22812#22812: BIO_new_file("/etc/ssl/private/ssl-chain-domain-$tld.pem") 失败(SSL: error:02001002:system library:fopen:No 这样的文件或directory:fopen('/etc/ssl/private/ssl-chain-domain-$tld.pem','r') error:2006D080:BIO routines:BIO_new_file:no 这样的文件

显然,没有发生 var 替换。 $1 也不行。

Nginx docs:

Variables should not be used as template macros. Variables are evaluated in the run-time during the processing of each request

换句话说:Nginx 不会为每个请求单独加载证书,因此不会为此使用变量。您需要明确指定您的特定证书路径。

另外,这个问题可能属于Serverfault(但我不知道如何移动它)。