Nginx: [emerg] cannot load certificate. SSL: error:0480006C:PEM

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. https://crt.sh/?q=example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: hani.asuscomm.com

I ran this command: certbot run -n --nginx -d hani.asuscomm.com

It produced this output:
certbot run -v -n --nginx -d hani.asuscomm.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Certificate not yet due for renewal
Keeping the existing certificate
Deploying certificate
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default
Successfully deployed certificate for hani.asuscomm.com to /etc/nginx/sites-enabled/default
Rolling back to previous server configuration...
An error occurred and we failed to restore your config and restart your server. Please post to Help - Let's Encrypt Community Support with details about your configuration and this error you received.
Encountered exception during recovery: certbot.errors.MisconfigurationError: nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
nginx: [emerg] still could not bind()

NEXT STEPS:

  • The certificate was saved, but could not be installed (installer: nginx). After fixing the error shown below, try installing it again by running:
    certbot install --cert-name hani.asuscomm.com

nginx restart failed:
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/hani.asuscomm.com/fullchain.pem": PEM_read_bio_X509_AUX() failed (SSL: error:0480006C:PEM routines::no start line:Expecting: TRUSTED CERTIFICATE)

Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

My web server is (include version): nginx/1.18.0 (Ubuntu)

The operating system my web server runs on is (include version): Ubuntu 22.04.2 LTS

My hosting provider, if applicable, is: hosted on personal machine

I can login to a root shell on my machine (yes or no, or I don't know): yes

I'm using a control panel to manage my site (no, or provide the name and version of the control panel): Site is gitlab-ce server

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): certbot 2.6.0

Hi @hfanous, and welcome to the LE community forum :slight_smile:

Let's start by looking at this file:

And the outputs of:
ls -l /etc/letsencrypt/live/*
ls -l /etc/letsencrypt/live/hani.asuscomm.com/*
ls -l /etc/letsencrypt/archive/hani.asuscomm.com/*

4 Likes

Thanks for looking into this for me. Here is the info you asked for:

ls -l /etc/letsencrypt/live/*

-rw-r--r-- 1 root root  740 Oct 31  2022 /etc/letsencrypt/live/README

/etc/letsencrypt/live/hani.asuscomm.com:
total 20
lrwxrwxrwx 1 root root   41 Oct 31  2022 cert.pem -> ../../archive/hani.asuscomm.com/cert1.pem
-rw-r--r-- 1 root root 5743 Apr  1 00:48 cert.pem-staging
lrwxrwxrwx 1 root root   42 Oct 31  2022 chain.pem -> ../../archive/hani.asuscomm.com/chain1.pem
lrwxrwxrwx 1 root root   46 Oct 31  2022 fullchain.pem -> ../../archive/hani.asuscomm.com/fullchain1.pem
-rw------- 1 root root 1675 Jun  1 00:48 letsencrypt_account_private_key.pem
lrwxrwxrwx 1 root root   44 Oct 31  2022 privkey.pem -> ../../archive/hani.asuscomm.com/privkey1.pem
-r-------- 1 root root 1675 Oct 31  2022 privkey.pem-staging
-rw-r--r-- 1 root root  692 Oct 31  2022 README

ls -l /etc/letsencrypt/live/hani.asuscomm.com/*

lrwxrwxrwx 1 root root   41 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/cert.pem -> ../../archive/hani.asuscomm.com/cert1.pem
-rw-r--r-- 1 root root 5743 Apr  1 00:48 /etc/letsencrypt/live/hani.asuscomm.com/cert.pem-staging
lrwxrwxrwx 1 root root   42 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/chain.pem -> ../../archive/hani.asuscomm.com/chain1.pem
lrwxrwxrwx 1 root root   46 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/fullchain.pem -> ../../archive/hani.asuscomm.com/fullchain1.pem
-rw------- 1 root root 1675 Jun  1 00:48 /etc/letsencrypt/live/hani.asuscomm.com/letsencrypt_account_private_key.pem
lrwxrwxrwx 1 root root   44 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/privkey.pem -> ../../archive/hani.asuscomm.com/privkey1.pem
-r-------- 1 root root 1675 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/privkey.pem-staging
-rw-r--r-- 1 root root  692 Oct 31  2022 /etc/letsencrypt/live/hani.asuscomm.com/README

ls -l /etc/letsencrypt/archive/hani.asuscomm.com/*

-rw-r--r-- 1 root root 5597 May  5 00:48 /etc/letsencrypt/archive/hani.asuscomm.com/cert1.pem
-rw-r--r-- 1 root root 3749 Oct 31  2022 /etc/letsencrypt/archive/hani.asuscomm.com/chain1.pem
-rw-r--r-- 1 root root 1708 Oct 31  2022 /etc/letsencrypt/archive/hani.asuscomm.com/fullchain1.pem
-rw------- 1 root root 1708 Oct 31  2022 /etc/letsencrypt/archive/hani.asuscomm.com/privkey1.pem
1 Like

And, can you show the /etc/nginx/sites-enabled/default file?

3 Likes

Hello,  Here is the sites-enabled/defaults file:



cat /etc/nginx/sites-enabled/default 
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#       include snippets/fastcgi-php.conf;
#
#       # With php-fpm (or other unix sockets):
#       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#       # With php-cgi (or other tcp sockets):
#       fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#       deny all;
#}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

Can you check to see if there are multiple instances of nginx running?

Have you restarted the server recently?
If not, can you?

4 Likes

You are absolutely right. The problem is not caused by letsencrypt/cerbot but by gitlab-ce which runs its own version of nginx. During configuration or upgrade it supposed to shutdown nginx update the files and then restart nginx. It fails to shut it down and it attempts to restart and this causes the failure.

The shutdown/restart is invoked during upgrades causing upgrades to fail with that error message. Attempting to renew the certificate using certbot also failed because nginx started by gitlab keeps running.

The workaround is to manually kill nginx before an upgrade.

Thanks for the help

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.