Renew failure for certificate

Hey people,
i have a problem with the renewal for the letsencrypt certificate for my nextcloud which is running on my raspberry pi.
If i try to renew the certificate (“sudo certbot renew”) the following error appears:

Attempting to renew cert (powercloud.spdns.de) from /etc/letsencrypt/renewal/powercloud.spdns.de.conf produced an unexpected error: Failed authorization procedure. powercloud.spdns.de (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://powercloud.spdns.de/.well-known/acme-challenge/ft6thPshxbn7nuxNECz2fmPSUpGtBKGNF3DmQAJFWME [31.16.141.112]: “\r\n403 Forbidden\r\n<body bgcolor=“white”>\r\n

403 Forbidden

\r\n
”. Skipping.

Detail: Invalid response from
https://powercloud.spdns.de/.well-known/acme-challenge/ft6thPshxbn7nuxNECz2fmPSUpGtBKGNF3DmQAJFWME

My guess is, that it is some kind of permission error, the certbot can’t reach the well-known directory to verify my server. I already created the test file in /var/www/html/.well-known/acme-challenge and if i try to reach it via https://powercloud.spdns.de/.well-known/acme-challenge/1234 a 403 forbidden error occurs.
I’m not really deep into the topic and would appreaciate any help to set the right permissions.
Thanks already.
:slight_smile:

1 Like

I see two things happening there.

  1. the HTTP request was redirected to HTTPS (that doesn’t need to happen for challenge requests)
  2. the HTTPS request was forbidden with error 403 (authentication required).

May we see your HTTP vhost config block?

At its’ simplest, you will need to add an exclusion for challenge requests from being redirected to HTTPS.
This can be done in different ways…
Which may depend on how your site is forcing the redirection.
If it is being redirect in a “location /” section, you simply need to add an additional section to bypass that redirection for challenge requests.
Like:

        location /.well-known/acme-challenge/ {
            try_files $uri =404;
        }#location

But this new location may also need to include a root statement - depending on where your server block root statement is located.
If your root statement is global to the entire server block you are good to go.
If your root statement is placed within the “location /” section, then this section will also need one.
[you can copy, and use, the one used in the “location /” section]

Ok i’m not sure i can follow you.
If i’m correct, my vhost config is found under: /etc/nginx/sites-available, the file is named “default” an besides:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/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;
}

everything there is commented out, the whole Virtual Host config is commented out in there. But i’m not quite sure if i’m even looking in the right directory.
To your next answer: where do I exactly place this bypass? So in which file do I add it and how do i find out where my server block root statement is located?

Thanks already for your help :slight_smile:

There must be another file - one that does the redirection…
Please show:
ls -l /etc/nginx/sites-enabled/

 wget http://powercloud.spdns.de/
--2019-11-10 12:45:59--  http://powercloud.spdns.de/
Resolving powercloud.spdns.de (powercloud.spdns.de)... 31.16.141.112
Connecting to powercloud.spdns.de (powercloud.spdns.de)|31.16.141.112|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://powercloud.spdns.de/ [following]

There is also a file named default and it shows the following content:

upstream php-handler {
 #server 127.0.0.1:9000;
 server unix:/var/run/php/php7.3-fpm.sock;
}

server {
 listen 80;
 listen [::]:80;
 server_name powercloud.spdns.de;
 # enforce https
 return 301 https://$server_name$request_uri;
 #root /var/www/html/;
}

server {
 listen 443 ssl http2;
 listen [::]:443 ssl http2;
 server_name powercloud.spdns.de;

 ssl_certificate /etc/letsencrypt/live/powercloud.spdns.de/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/powercloud.spdns.de/privkey.pem;

# Add headers to serve security related headers
 # Before enabling Strict-Transport-Security headers please read into this
 # topic first.
 add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
 #
 # WARNING: Only add the preload option once you read about
 # the consequences in https://hstspreload.org/. This option
 # will add the domain to a hardcoded list that is shipped
 # in all major browsers and getting removed from this list
 # could take several months.
 add_header X-Content-Type-Options nosniff;
 add_header X-XSS-Protection "1; mode=block";
 add_header X-Robots-Tag none;
 add_header X-Download-Options noopen;
 add_header X-Permitted-Cross-Domain-Policies none;
 add_header Referrer-Policy "no-referrer" always;

# Path to the root of your installation
 root /var/www/html/;

location = /robots.txt {
 allow all;
 log_not_found off;
 access_log off;
 }

# The following 2 rules are only needed for the user_webfinger app.
 # Uncomment it if you're planning to use this app.
 #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
 #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
 # last;

location = /.well-known/carddav {
 return 301 $scheme://$host/remote.php/dav;
 }
 location = /.well-known/caldav {
 return 301 $scheme://$host/remote.php/dav;
 }

# set max upload size
 client_max_body_size 512M;
 fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
 gzip on;
 gzip_vary on;
 gzip_comp_level 4;
 gzip_min_length 256;
 gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
 gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# Uncomment if your server is build with the ngx_pagespeed module
 # This module is currently not supported.
 #pagespeed off;

location / {
 rewrite ^ /index.php$uri;
 }

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
 deny all;
 }
 location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
 deny all;
 }

location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
 fastcgi_split_path_info ^(.+\.php)(/.*)$;
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_param HTTPS on;
 #Avoid sending the security headers twice
 fastcgi_param modHeadersAvailable true;
 fastcgi_param front_controller_active true;
 fastcgi_pass php-handler;
 fastcgi_intercept_errors on;
 fastcgi_request_buffering off;
 }

location ~ ^/(?:updater|ocs-provider)(?:$|/) {
 try_files $uri/ =404;
 index index.php;
 }

# Adding the cache control header for js and css files
 # Make sure it is BELOW the PHP block
 location ~ \.(?:css|js|woff|svg|gif)$ {
 try_files $uri /index.php$uri$is_args$args;
 add_header Cache-Control "public, max-age=15778463";
 # Add headers to serve security related headers (It is intended to
 # have those duplicated to the ones above)
 # Before enabling Strict-Transport-Security headers please read into
 # this topic first.
 # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
 #
 # WARNING: Only add the preload option once you read about
 # the consequences in https://hstspreload.org/. This option
 # will add the domain to a hardcoded list that is shipped
 # in all major browsers and getting removed from this list
 # could take several months.
 add_header X-Content-Type-Options nosniff;
 add_header X-XSS-Protection "1; mode=block";
 add_header X-Robots-Tag none;
 add_header X-Download-Options noopen;
 add_header X-Permitted-Cross-Domain-Policies none;
 # Optional: Don't log access to assets
 access_log off;
 }

location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
 try_files $uri /index.php$uri$is_args$args;
 # Optional: Don't log access to other assets
 access_log off;
 }
}

That is difficult to read.
Please add three back ticks on a line before and after your text file
Like:
```
<your file>
```

[just go back and edit the post above]

This is the spot:

Modify that section like:

server {
 listen 80;
 listen [::]:80;
 server_name powercloud.spdns.de;
 location /.well-known/acme-challenge/ {
  root /var/www/html/;
  try_files $uri =404;
 }#location
 location / {
  # enforce https
  return 301 https://$server_name$request_uri;
  #root /var/www/html/;
 }#location
}#server

[edit: I’ve tweaked it slightly from the first post]

Wow thank you so much, it all works fine now!! The renewal went through just fine.
Thanks for your time and effort! :smiley:

1 Like

Cheers from Miami :slight_smile:
[Maybe you can now be a somewhat happierUnicorn - LOL]

1 Like

Yeah greetings from Germany, not mad anymore just until the next problem will appear :smiley: :smiley:

1 Like