大网数据广告活动
服务器运维问答

Let’s Encrypt certbot cannot complete verification due to Nginx server config

· 52CE 我爱测

For an application I need the following line in my location block: rewrite ".*" /server.php break; This causes certbot fail to verify the domain. To install the SSL cert I commented that line and certbot worked fine. Now, the iss…

问题原文

原帖链接 · Majid Fouladpour · CC BY-SA 3.0

For an application I need the following line in my location block:

rewrite ".*" /server.php break;

This causes certbot fail to verify the domain. To install the SSL cert I commented that line and certbot worked fine. Now, the issue is renewal is automated and will fail if I uncomment the line.

Is there a way to have a dedicated location just for Let's Encript's verification? If so, what?

Here is the full block with the problem line commented:

location / { 
    try_files $uri $uri/ =404; 
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    include fastcgi_params;
    fastcgi_param USE_INSTANCE 'd1';
    fastcgi_param SCRIPT_FILENAME $request_filename;
    #rewrite ".*" /server.php break; 
}

If you wonder why I am not limiting the match pattern to ~ \.php$, it is because the config belongs to my api.host.com endpoint which will only receive requests that need to be routed to a PHP script.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

I created a separate location block for certbot.

location /.well-known/acme-challenge/ {
    root /var/www;
    try_files $uri =404;
}

(Note that I use the same document root for every virtual host, which is outside the normal document root, so certbot is never writing anything to the web sites' actual directories.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。