Renew certificate in a port other than 443

Hello,

I have problems in renew certificates other than port 443. I think the problem is when certbot try renew the certificate, it try to connect in standard port 443, but my domain is in 447 port. Then there is an error, because it don’t find challenge correct.

My domain is:

https://webmail.programadorderiego.com:447

I ran this command:

certbot -q renew

It produced this output:

Jul 29 03:23:36 h2747393 certbot[11576]: Attempting to renew cert (webmail.programadorderiego.com) from /etc/letsencrypt/renewal/webmail.programadorderiego.com.conf produced an unexpected error: Failed authorization procedure. webmail.programadorderiego.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://www.programadorderiego.com/.well-known/acme-challenge/YG0UCYvVeRSEbfMT5IqRHhnz9X1j68x8aKD3IL17CEg [85.214.19.62]: “\r\n404 Not Found\r\n<body bgcolor=“white”>\r\n

404 Not Found

\r\n
”. Skipping.
Jul 29 03:23:59 h2747393 certbot[11576]: /etc/letsencrypt/live/webmail.programadorderiego.com/fullchain.pem (failure)

My web server is (include version):

NGINX 1.10.3

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

Ubuntu 16.04.3 LTS

My hosting provider, if applicable, is:

No.

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):

No.

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

certbot 0.28.0

Hi @yoburtu

to validate a domain via http-01 validation, Letsencrypt checks the port 80 of that domain, there a file in /.well-known/acme-challenge. There may be a redirect to another port 80 or to port 443. Letsencrypt follows these redirects. Other ports are ignored.

Your configuration ( https://check-your-website.server-daten.de/?q=webmail.programadorderiego.com ):

Domainname Http-Status redirect Sec. G
http://webmail.programadorderiego.com/
85.214.19.62 301 https://www.programadorderiego.com/ 0.000 E
http://www.webmail.programadorderiego.com/
85.214.19.62 301 https://www.programadorderiego.com/ 0.000 E
https://webmail.programadorderiego.com/
85.214.19.62 200 9.454 N
Certificate error: RemoteCertificateNameMismatch
https://www.webmail.programadorderiego.com/
85.214.19.62 200 9.296 N
Certificate error: RemoteCertificateNameMismatch
https://www.programadorderiego.com/ 200 9.374 I
http://webmail.programadorderiego.com/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de
85.214.19.62 301 https://www.programadorderiego.com/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 0.013 E
Visible Content: 301 Moved Permanently nginx/1.10.3 (Ubuntu)
http://www.webmail.programadorderiego.com/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de
85.214.19.62 301 https://www.programadorderiego.com/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 0.017 E
Visible Content: 301 Moved Permanently nginx/1.10.3 (Ubuntu)
https://www.programadorderiego.com/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 404 9.186 A
Not Found
Visible Content: 404 Not Found nginx/1.10.3 (Ubuntu)

You have a redirect. But to your main domain. There

is the same. Letsencrypt checks your main domain, not your webmail subdomain.

So the apache plugin doesn't understand your configuration. Because the plugin adds location definitions, so a redirect should be ignored.

What says

apachectl -S

I have NGINX 1.10.3.

My nginx conf for this domain is in port 447:

server {

	client_max_body_size 30M;

	root /home/user/webmail;

	index index.html index.htm index.php;

	server_name webmail.programadorderiego.com

	access_log /home/user/log/webmail-access.log;
	error_log /home/user/log/webmail-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-webmail.sock;
	}


    listen 447 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/webmail.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/webmail.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

Best regards.

Yep, sorry - then

nginx -T

is required.

Your port 447 is ignored. Looks like there is a standard port 80 that answers.

Perhaps create an explicit port 80 with

server_name webmail.programadorderiego.com

so the nginx plugin can find your correct vHost. And share your config file from

/etc/letsencrypt/renewal

$ nginx -T

nginx: [warn] the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
nginx: [emerg] BIO_new_file("/etc/letsencrypt/live/admin.programadorderiego.com/fullchain.pem") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen(’/etc/letsencrypt/live/admin.programadorderiego.com/fullchain.pem’,‘r’) error:2006D002:BIO routines:BIO_new_file:system lib)
nginx: configuration file /etc/nginx/nginx.conf test failed

root@server:/etc/letsencrypt/renewal# cat webmail.programadorderiego.com.conf

renew_before_expiry = 30 days

version = 0.28.0
archive_dir = /etc/letsencrypt/archive/webmail.programadorderiego.com
cert = /etc/letsencrypt/live/webmail.programadorderiego.com/cert.pem
privkey = /etc/letsencrypt/live/webmail.programadorderiego.com/privkey.pem
chain = /etc/letsencrypt/live/webmail.programadorderiego.com/chain.pem
fullchain = /etc/letsencrypt/live/webmail.programadorderiego.com/fullchain.pem

Options used in the renewal process

[renewalparams]
account = bb28e9afb0b0f35b901d2a602596991f
authenticator = nginx
server = https://acme-v02.api.letsencrypt.org/directory
installer = nginx

Best regards.

Then use sudo. If that doesn't work, share your port 80 vHost. Or use it as template to create a correct port 80 vHost with that domain name.

Or switch to webroot:

https://certbot.eff.org/docs/using.html

That should always work with your redirect http -> https.

root@server:~# nginx -T

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
#user www-data;
user user user;
worker_processes 2;
pid /run/nginx.pid;

events {
	worker_connections 1024;
	multi_accept on;
	use epoll;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_requests 500;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/admin:
server {

        auth_basic "Heimdall Tech, S.L. Zona de Administracion";
        auth_basic_user_file /home/user/.htpasswd/admin;

	root /home/user/pro/admin;

	index index.html index.php;

	server_name admin.programadorderiego.com admin.programadoresderiego.com admin.programadorderiego.es;

	access_log /home/user/log/admin-access.log;
	error_log /home/user/log/admin-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}


    listen 444 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/admin.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/admin.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

# configuration file /etc/nginx/snippets/fastcgi-php.conf:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

# configuration file /etc/nginx/fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# configuration file /etc/letsencrypt/options-ssl-nginx.conf:
# This file contains important security parameters. If you modify this file
# manually, Certbot will be unable to automatically provide future security
# updates. Instead, Certbot will print and log an error message with a path to
# the up-to-date file that you will need to refer to when manually updating
# this file.

ssl_session_cache shared:le_nginx_SSL:1m;
ssl_session_timeout 1440m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";

# configuration file /etc/nginx/sites-enabled/default:
map $uri $redirect_https {
        /api/arduino.php        0;
        /api/regantes.php       0;
        default                 1;
}

server {

        if ($redirect_https = 0) {
                return 301 http://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.programadorderiego.com programadorderiego.com www.programadoresderiego.com programadoresderiego.com www.programadorderiego.es programadorderiego.es;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}


server {

	listen 80;

        if ($redirect_https = 1) {
                return 301 https://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.programadorderiego.com programadorderiego.com www.programadoresderiego.com programadoresderiego.com www.programadorderiego.es programadorderiego.es;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

}



# configuration file /etc/nginx/sites-enabled/fs:
server {

	root /home/user/fs;

	index index.html index.htm index.php;

	server_name fs.programadorderiego.com fs.programadoresderiego.com fs.programadorderiego.es;

	access_log /home/user/log/fs-access.log;
	error_log /home/user/log/fs-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-fs.sock;
	}


    listen 445 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/fs.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/fs.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}



# configuration file /etc/nginx/sites-enabled/heimdallsl:
map $uri $redirect_https {
        /api/arduino.php        0;
        /api/regantes.php       0;
        default                 1;
}

server {

        if ($redirect_https = 0) {
                return 301 http://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name heimdallsl.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/heimdallsl.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/heimdallsl.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}


server {

	listen 80;

        if ($redirect_https = 1) {
                return 301 https://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name heimdallsl.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

}



# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# configuration file /etc/nginx/sites-enabled/node1:
server {
	listen 8081;

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name 85.214.147.142;

	access_log /home/user/log/node1-access.log;
	error_log /home/user/log/node1-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }
}


# configuration file /etc/nginx/sites-enabled/test:
server {

	listen 7000;

        auth_basic "Heimdall Tech, S.L. TESTSITE";
        auth_basic_user_file /home/user/.htpasswd/admin;

	root /home/user/test/docroot;

	index index.html index.php;

	server_name test.programadorderiego.com test.programadorderiego.es test.programadoresderiego.com;

	access_log /home/user/log/test-access.log;
	error_log /home/user/log/test-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-test.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm-test.sock;
		}
        }

}

# configuration file /etc/nginx/sites-enabled/test-admin:
server {

	listen 80;

        auth_basic "Heimdall Tech, S.L. Zona de Administracion. TESTSITE";
        auth_basic_user_file /home/user/.htpasswd/admin;

	root /home/user/test/admin;

	index index.html index.php;

	server_name test-admin.programadorderiego.com test-admin.programadoresderiego.com test-admin.programadorderiego.es;

	access_log /home/user/log/test-admin-access.log;
	error_log /home/user/log/test-admin-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-test.sock;
	}

}


# configuration file /etc/nginx/sites-enabled/test-fs:
server {

	root /home/user/fs.test;

	index index.html index.htm index.php;

	server_name fs-test.programadorderiego.com fs-test.programadoresderiego.com fs-test.programadorderiego.es;

	access_log /home/user/log/fs-test-access.log;
	error_log /home/user/log/fs-test-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-fs.sock;
	}


    listen 446 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/fs-test.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/fs-test.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}



# configuration file /etc/nginx/sites-enabled/webmail:
server {

	client_max_body_size 30M;

	root /home/user/roundcubemail;

	index index.html index.htm index.php;

	server_name webmail.programadorderiego.com webmail.programadoresderiego.com webmail.programadorderiego.es;

	access_log /home/user/log/webmail-access.log;
	error_log /home/user/log/webmail-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-webmail.sock;
	}


    listen 447 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/webmail.programadorderiego.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/webmail.programadorderiego.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


# configuration file /etc/nginx/sites-enabled/webmail-test:
server {

	listen 80;

	root /home/user/roundcubemail.test;

	index index.html index.htm index.php;

	server_name webmail-test.programadorderiego.com webmail-test.programadoresderiego.com webmail-test.programadorderiego.es;

	access_log /home/user/log/webmail-test-access.log;
	error_log /home/user/log/webmail-test-error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm-webmail.sock;
	}

}


# configuration file /etc/nginx/sites-enabled/www.heimdallsl.com:
map $uri $redirect_https {
        /api/arduino.php        0;
        /api/regantes.php       0;
        default                 1;
}

server {

        if ($redirect_https = 0) {
                return 301 http://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.heimdallsl.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.heimdallsl.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.heimdallsl.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}


server {

	listen 80;

        if ($redirect_https = 1) {
                return 301 https://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.heimdallsl.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

}



# configuration file /etc/nginx/sites-enabled/www.misprogramadores.com:
map $uri $redirect_https {
        /api/arduino.php        0;
        /api/regantes.php       0;
        default                 1;
}

server {

        if ($redirect_https = 0) {
                return 301 http://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.misprogramadores.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.misprogramadores.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.misprogramadores.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {

	listen 80;

        if ($redirect_https = 1) {
                return 301 https://$server_name$request_uri;
        }

	root /home/user/pro/docroot;

	index index.html index.php;

	server_name www.misprogramadores.com;

	access_log /home/user/log/access.log;
	error_log /home/user/log/error.log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}

        # Comunicacion con Arduino
        location ^~ /api {

                auth_basic "Heimdall Tech, S.L. Arduino";
                auth_basic_user_file /home/user/.htpasswd/arduino;

		location ~ \.php$ {
			include snippets/fastcgi-php.conf;
			fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		}
        }

}

I have tested with webroot, but don’t work:

root@server:~# certbot certonly --webroot -w /home/user/webmail/.certbot -d webmail.programadorderiego.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for webmail.programadorderiego.com
Using the webroot path /home/user/webmail/.certbot for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. webmail.programadorderiego.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://www.programadorderiego.com/.well-known/acme-challenge/RhKMvjvHwGIEsFKbqeXghrp-pS-HOSM5ebA0FrG2_58 [85.214.19.62]: "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>"

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: webmail.programadorderiego.com
   Type:   unauthorized
   Detail: Invalid response from
   https://www.programadorderiego.com/.well-known/acme-challenge/RhKMvjvHwGIEsFKbqeXghrp-pS-HOSM5ebA0FrG2_58
   [85.214.19.62]: "<html>\r\n<head><title>404 Not
   Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404
   Not Found</h1></center>\r\n<hr><center>"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.

If you use the wrong webroot, that can't work.

I have configured yet all virtual servers in 443 port. Now I have other error:


# certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: heimdallsl.com
2: www.heimdallsl.com
3: misprogramadores.com
4: www.misprogramadores.com
5: programadorderiego.com
6: programadorderiego.es
7: admin.programadorderiego.com
8: fs.programadorderiego.com
9: fs-test.programadorderiego.com
10: test.programadorderiego.com
11: test-admin.programadorderiego.com
12: webmail.programadorderiego.com
13: webmail-test.programadorderiego.es
14: webmail-test.programadorderiego.com
15: www.programadorderiego.com
16: www.programadorderiego.es
17: programadoresderiego.com
18: webmail-test.programadoresderiego.com
19: www.programadoresderiego.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 12
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for webmail.programadorderiego.com
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. webmail.programadorderiego.com (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://webmail.programadorderiego.com/.well-known/acme-challenge/boSP9ea6HnrhQRdBppem-LzUKDR5LFUvQVJnX2BHvbQ [85.214.19.62]: "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>"

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: webmail.programadorderiego.com
   Type:   unauthorized
   Detail: Invalid response from
   https://webmail.programadorderiego.com/.well-known/acme-challenge/boSP9ea6HnrhQRdBppem-LzUKDR5LFUvQVJnX2BHvbQ
   [85.214.19.62]: "<html>\r\n<head><title>404 Not
   Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404
   Not Found</h1></center>\r\n<hr><center>"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.

Who creates the “.well-known/acme-challenge/boSP9ea6HnrhQRdBppem-LzUKDR5LFUvQVJnX2BHvbQ” file??.

Best regards.

By the way, I am executing “certbot” in a different server of web server nginx. Can this be the problem?.

Best regards.

That's the validation file Certbot creates. Letsencrypt checks that file.

Please read the basics:

then about challenge types:

Certbot must be able to create the challenge file in the correct place. So if you run certbot on another server, that can't work.

2 Likes

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