You need to enable JavaScript to run this app. Ubuntu Focal中Nginx为Laravel+PHP8.0配置Let's Encrypt SSL的报错及方案
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Focal中Nginx为Laravel+PHP8.0配置Let's Encrypt SSL的报错及方案

现有Nginx配置

我目前正在使用Laravel官方提供的默认生产部署配置:

server {
    listen 80;
    server_name www.example.com;
    root /srv/www/example/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found; }
    location = /robots.txt  { access_log off; log_not_found; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
问题描述

我需要调整这份配置,让站点能正常使用Let's Encrypt提供的SSL服务,但在当前配置下运行certbot命令申请证书时遇到了报错,校验环节失败:

# 执行的证书申请命令
sudo certbot --nginx -d www.example.com

# 完整输出日志
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.example.com
Waiting for verification...
Challenge failed for domain www.example.com
http-01 challenge for www.example.com
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
 - 服务器返回的错误信息如下:
   域名:www.example.com
   错误类型:unauthorized
   错误详情:访问校验地址 http://www.example.com/.well-known/acme-challenge/KLiVD9nJaMVqJoljNziftqSJXFXCEXsV5mf_d9WthdM (对应IP 123.123.123.3)时返回无效响应,页面为404 Not Found的HTML报错页。

证书申请工具附带的初步排查提示:请确认域名输入正确,且域名对应的DNS A/AAAA记录与服务器实际公网IP匹配。

服务器网络连通性验证

我从外部网络环境扫描了服务器的端口开放情况,扫描结果如下:

# 执行的端口扫描命令
nmap 123.123.123.3

# 扫描结果
Starting Nmap 7.70 ( https://nmap.org ) at 2020-12-14 11:13 CET
Nmap scan report for 213.163.173.3
Host is up (0.0061s latency).
Not shown: 997 filtered ports
PORT    STATE  SERVICE
80/tcp  open   http
113/tcp closed ident
443/tcp open   https

内容的提问来源于stack exchange,提问作者DevonDahon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.13 03:45:03