Ubuntu 18.04 NGINX and Certbot SSL issues

March 13, 2019 1.5k views
Ubuntu 18.04 Nginx

Hi all, so I just set up my first droplet on DigitalOcean and completed the installation of iRedMail and it’s working fine however my attempt to install and enable certbot is giving me no results.

I’ve checked several guides including this one and cannot seem to identify the issue. I have certbot running on another server, here I am using Ubuntu 18.04 NOT 16.04 which may affect sites-available server blocks.

I installed certbot:

apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
sudo apt-get install certbot python-certbot-nginx

certbot certonly --nginx --dry-run -d mail.domain1.com -d mail.domain2.com
certbot certonly --nginx -d mail.domain1.com -d mail.domain2.com
reboot
root@mail:~# certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): mail.domain1.com mail.domain2.com
Cert not yet due for renewal
You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/mail.domain1.com.conf)

What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Renewing an existing certificate
Could not automatically find a matching server block for mail.domain1.com. Set the `server_name` directive to use the Nginx installer.

IMPORTANT NOTES:
 - Unable to install the certificate
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mail.domain1.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mail.domain1.com/privkey.pem
   Your cert will expire on 2019-06-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"```

```nginx -t
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
crontab -e
    15 3 * * * /usr/bin/certbot renew --quiet
    15 3 * * 5 /usr/bin/certbot renew renew >> /var/log/le-renew.log

In /etc/nginx/sites-available I have two files:

00-default-ssl.conf (content below)

# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
    listen 443;
    server_name _;

    root /var/www/html;
    index index.php index.html;

    include /etc/nginx/templates/misc.tmpl;
    include /etc/nginx/templates/ssl.tmpl;
    include /etc/nginx/templates/iredadmin.tmpl;
    include /etc/nginx/templates/roundcube.tmpl;
    include /etc/nginx/templates/sogo.tmpl;
    include /etc/nginx/templates/netdata.tmpl;
    include /etc/nginx/templates/php-catchall.tmpl;
    include /etc/nginx/templates/stub_status.tmpl;
}


```00-default.conf (content below)

Note: This file must be loaded before other virtual host config files,

HTTP

server {
# Listen on ipv4
listen 80;

# Listen on ipv6.
# Note: this setting listens on both ipv4 and ipv6 with Nginx release
#       shipped in some Linux/BSD distributions.
#listen [::]:80;

server_name _;

# Redirect all insecure http:// requests to https://
return 301 https://$host$request_uri;

}“`

Note there is no ‘mail.domain1.com’ or 'mail.domain2.com’ site block.

root@mail:/etc/nginx/sites-available# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

I’m a bit lost where to look for a solution. Do I have a conflict with letsencrypt and certbot names? Have I incorrectly/incompletely setup sites-available and sites-enabled? All suggestions appreciated.

1 Answer

Greetings!

If you’ve installed iRedMail, I do not recommend following other instructions for configuring the SSL. Any instruction for it should be iRedMail specific, because that software will control the web server and may not use an OS-default setup. It may also overwrite configurations on update. I found a guide for setting this up though, and it may be helpful:

https://docs.iredmail.org/letsencrypt.html

Jarland

Have another answer? Share your knowledge.