让我们encryption证书和NGINX – 找不到证书或密钥指令

我的服务器运行在LEMP堆栈Ubuntu 16.04和最后一个版本的nginx

我已经在我的服务器上为以下域和子域安装了SSL证书: example.comdomain1.example.com和一切工作正常。

我试图实现的

我想为domain2.example.com创build一个新的证书

为此,我尝试了这个命令:

sudo certbot --nginx -d example.com -d domain1.example.com -d domain2.example.com --expand

错误信息

在/etc/nginx/sites-enabled/example.com中找不到set(['www.example.com','* .example.com','example.com'))的证书或密钥指令。 VirtualHost没有被修改。

nginxconfiguration

 server { # SSL configuration listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-example.com.conf; include snippets/ssl-params.conf; root /var/www/laravel/public; index index.php index.html index.htm; server_name example.com *.example.com www.example.com ; } 

问题

我究竟做错了什么 ? 我如何重新创build证书来添加domain2

这是我必须做的。

  1. 首先键入certbot certificatesfind现有的certbot certificates
  2. 然后确定您想要expand的证书
  3. 通过键入sudo certbot certonly --cert-name example.com -d example.com -d domain1.example.com -d domain2.example.com --expand来更新证书sudo certbot certonly --cert-name example.com -d example.com -d domain1.example.com -d domain2.example.com --expand
  4. select2: Place files in webroot directory (webroot)
  5. input新的webroot ,这是我/var/www/laravel

对我来说,我进入了/etc/nginx/sites-enabled文件夹,并手动删除了错误的sym-linked虚拟主机文件,我以为我之前已经删除。 惊喜,他们仍然在那里。 所以请确保在该文件夹中执行sudo rm -rf [filename] 。 然后通过sudo nginx -s reload重新启动nginx sudo nginx -s reload并再次运行certbot命令,并且应该是GTG。

最好的方法之一是使用webroot插件(描述https://certbot.eff.org/#centosrhel7-other )。 我build议遵循下面的方法:

  1. 将以下位置指令添加到主机(服务器块),您要通过certbot进行处理并获取证书:

     location /.well-known { root /usr/share/nginx/html; } 
  2. 安装certbot

  3. 执行certbot certonly命令
  4. 遵循指示。 selectauthentication的“webroot方式”(第二选项)。 而当你要求www-root为你的域input/usr/share/nginx/html (如位置指令根目录)。
  5. 完成后,您可以在/etc/letsencrypt/live/youdomain.com/fullchain.pemfind您的证书。
  6. 添加到服务器块:

     ssl on; ssl_certificate /etc/letsencrypt/live/youdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/youdomain.com/privkey.pem; 

这就是所有;)之后,您可以通过运行certbot renew命令轻松更新证书。

怎么运行的?

当我们添加位置指令时,我们为/.well-known位置select自定义根文件夹。 Certbot在.well-known目录和外部authentication服务器(ACME CA)里面创build文件检查这个文件夹中的文件。 如果您pipe理多个域或使用nginx作为代理(!),那么为/.well-known位置使用一个通用根是非常有用的,因为在这种情况下,您可能没有使用nginx的计算机上的根目录(例如,您已经安装了nginx一个VPS作为安装在另一个VPS上的Apache的代理)。

祝你好运。