Nginx – Let’s encrypt certificate and NGINX – Cannot find a cert or key directive

certbotlets-encryptnginxubuntu-16.04

My server runs on a LEMP Stack Ubuntu 16.04 and last version of nginx

I already have a SSL certificate installed on my server for the following domains and subdomains : example.com, domain1.example.com and everything is working fine.

What I try to achieve

I'd like to create a new certificate for domain2.example.com

To do so, I tried this command:

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

Error message

Cannot find a cert or key directive in /etc/nginx/sites-enabled/example.com for set(['www.example.com', '*.example.com', 'example.com']). VirtualHost was not modified.

nginx config

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 ;
}

Questions

What am I doing wrong ? How can I recreate the certificate to add the domain2 ?

Best Answer

Here is what I had to do.

  1. First find the existing certificates by typing certbot certificates
  2. Then identify the certificate you wish to expand
  3. Update the certificate by typing sudo certbot certonly --cert-name example.com -d example.com -d domain1.example.com -d domain2.example.com --expand.
  4. Select 2: Place files in webroot directory (webroot)
  5. Enter new webroot which was for me /var/www/laravel