将 certbot-auto 用于 nginx

using certbot-auto for nginx

我有一个 nginx 运行。 现在我想让我的 nginx 使用 SSL:

certbot-auto --nginx -d my.domain.com -n --agree-tos --email admin@mail.com

输出:

Performing the following challenges:
tls-sni-01 challenge for my.domain.com
Cleaning up challenges
Cannot find a VirtualHost matching domain my.domain.com.

my.domain.com 指向我服务器的IP。这是它的 DNS 名称。 我究竟做错了什么?我已经为 apache 做了这个并且工作正常。我的 nginx 是 运行(我无法在 certbot-auto 之后手动重启它,但是当我使用 certbot-auto --apache

时没有必要

在我的例子中,我必须添加 "server_name" 行,因为它不在我的 nginx 配置中,所以它在我 运行 时给我错误消息 "Cannot find a VirtualHost matching domain my.domain.com":

certbot --nginx

确保这在您的配置中:

server {
    server_name my.domain.com;
    ....
}

您可能在 sites-enabled 文件夹中丢失了一些服务器块(虚拟主机)文件。检查您的配置文件是否存在于 /etc/nginx/sites-available /etc/nginx/sites-enabled 中。如果它们不在启用站点的文件夹中,请为它们创建符号链接:

$ sudo ln -s /etc/nginx/sites-available/my.domain.com /etc/nginx/sites-enabled/

添加您的站点,检查配置错误并重新启动 nginx:

$ sudo certbot --nginx -d my.domain.com
$ sudo nginx -t
$ sudo service nginx restart