如何使用certbot修复错误设置SSL?

时间:2018-12-09 13:49:01

标签: ssl certbot

我尝试使用Kubuntu 18在Digital Ocean下为我的php / laravel应用程序设置ssl 就像这篇文章 https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04

但是尝试使用certbot获取免费的SSL证书时出现错误:

@Id

products-catalog.nilov-sergey-demo-apps.tk-这是我在freenom.com上获得的域名,通过搜索我发现了一个提示 我需要为www子域添加A记录

我试图将新记录添加为https://imgur.com/a/ijFxlzN 但是尝试让我浏览此页面:

# sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
22/tcp                     ALLOW       Anywhere                                                                                                                                                                        
Apache Full (v6)           ALLOW       Anywhere (v6)                                                                                                                                                                   
443 (v6)                   ALLOW       Anywhere (v6)                                                                                                                                                                   
80 (v6)                    ALLOW       Anywhere (v6)                                                                                                                                                                   
22/tcp (v6)                ALLOW       Anywhere (v6)                                                                                                                                                                   

# sudo certbot --apache -d products-catalog.nilov-sergey-demo-apps.tk -d www.products-catalog.nilov-sergey-demo-apps.tk                                                                              
Saving debug log to /var/log/letsencrypt/letsencrypt.log                                                                                                                                                               
Plugins selected: Authenticator apache, Installer apache                                                                                                                                                               
Obtaining a new certificate                                                                                                                                                                                            
Performing the following challenges:
http-01 challenge for products-catalog.nilov-sergey-demo-apps.tk
http-01 challenge for www.products-catalog.nilov-sergey-demo-apps.tk
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. www.products-catalog.nilov-sergey-demo-apps.tk (http-01): urn:ietf:params:acme:error:dns :: DNS problem: NXDOMAIN looking up A for www.products-catalog.nilov-sergey-demo-apps.tk

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: www.products-catalog.nilov-sergey-demo-apps.tk
   Type:   None
   Detail: DNS problem: NXDOMAIN looking up A for
   www.products-catalog.nilov-sergey-demo-apps.tk

怎么了?新记录可以解决我的问题吗?还是我需要以其他方式移动?

更新#2 在appache中的配置是:

• Error occured: Invalid value in dnsrecord

在/ etc / hosts中带有一行

 <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/lprods/public    
    ServerName products-catalog.nilov-sergey-demo-apps.tk
    ServerAlias products-catalog.nilov-sergey-demo-apps.tk

    <Directory /var/www/html/lprods/public>
      AllowOverride All
      Order Deny,Allow
      Allow from all
      Require all granted
    </Directory>

    Options FollowSymLinks
    DirectoryIndex index.php

    ErrorLog /var/www/html/lprods/storage/logs/error.log
    CustomLog /var/www/html/lprods/storage/logs/access.log combined
</VirtualHost>

可能是我的问题吗?

更新#3 我进行了更多评论,然后找到下一个:

我服务器的IP为138.68.107.4,在ssh下,我输入操作系统的控制台为

138.68.107.5  products-catalog.nilov-sergey-demo-apps.tk

但是在我的/ etc / hosts文件中,下一行指向该服务器上的其他主机:

ssh root@138.68.107.4

我将最后3行修改为:

# 127.0.0.1 localhost
127.0.0.1 localhost.localdomain localhost
138.68.107.4  box.example.com box

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

138.68.107.4  votes.nilov-sergey-demo-apps.tk
138.68.107.5  products-catalog.nilov-sergey-demo-apps.tk
138.68.107.6  csvp.nilov-sergey-demo-apps.tk
...

但是我仍然不确定那是有效值,因为我再次遇到下一个错误:

138.68.107.4  votes.nilov-sergey-demo-apps.tk
138.68.107.4  products-catalog.nilov-sergey-demo-apps.tk
138.68.107.4  csvp.nilov-sergey-demo-apps.tk

此错误的原因可能是/ etc / hosts中的IP错误或其他问题吗?

谢谢!

3 个答案:

答案 0 :(得分:1)

certbot抱怨:

DNS problem: NXDOMAIN looking up A for
www.products-catalog.nilov-sergey-demo-apps.tk

a)本地/etc/hosts文件不是公共DNS区域文件...只需添加域名;因为HTTP主机标头将虚拟主机分开:138.68.107.4 nilov-sergey-demo-apps.tk 使用DNS区域文件时,不必像在localhost.

上一样将它们添加到其中。

b),然后在没有不存在的certbot虚拟主机的情况下使用www命令:

sudo certbot --apache -d products-catalog.nilov-sergey-demo-apps.tk

修复DNS和虚拟主机,以便为www虚拟主机提供服务;那么他们应该为两者工作。预期会有A个“地址”记录;但是提供了CNAME“公用名”记录。要解决此问题,您只需将类型从CNAME更改为A,然后等待其分发即可。

亲自查看:non-wwwwwwHTTPS也完全不响应。

c)并修复虚拟主机配置,您必须添加适当的ServerAlias

ServerName products-catalog.nilov-sergey-demo-apps.tk
ServerAlias www.products-catalog.nilov-sergey-demo-apps.tk

答案 1 :(得分:1)

www.products-catalog.nilov-sergey-demo-apps.tk无法解析:

https://www.whatsmydns.net/#A/www.products-catalog.nilov-sergey-demo-apps.tk

enter image description here

因此,这不是服务器配置问题,您只需在DNS管理器中添加www.products-catalog子域记录,

或从certbot命令中删除:-d www.products-catalog.nilov-sergey-demo-apps.tk

答案 2 :(得分:1)

如果您使用{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Flutter", "request": "launch", "type": "dart", "args": [ "--flavor", "emulator" ] } ] } 运行certbot,然后使用--manual certonly选项运行,它将把证书“重新安装”到您的Apache服务器。

运行:

--apache

然后添加DNS TXT记录,并在sudo certbot --server https://acme-v02.api.letsencrypt.org/directory -d *.domain.com --manual --preferred-challenges dns-01 certonly 指令上单击“继续”。 完成后,您可以像这样运行一个简单的certbot

--apache install

这将要求重新安装证书,您可以选择它。