Everything to https://www.example.com

Previously i generated certificates for recover.ranqx.com and www.recover.ranqx.com. Unfortunately i didnt configure it properly and accessing https://www.recover.ranqx.com would give certificate warning.
so i ran: sudo certbot delete.
Then I configured some special setting at /etc/apache2/sites-enabled/configFile.conf

My domain is: recover.ranqx.com
I ran this command: sudo certbot --apache certonly -d www.recover.ranqx.com -d recover.ranqx.com

It produced this output:

My web server is (include version): apache2 v 2.4.18

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

My hosting provider, if applicable, is: AWS

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. using aws route53

I need help in configuring everything to https://www.example.com.

I ran the command to get just the certificate and in the apache error i see:
[ssl:emerg] [pid 23892] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned

sudo certbot --apache certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache

Which names would you like to activate HTTPS for?


1: recover.ranqx.com
2: www.recover.ranqx.com


Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter ā€˜cā€™ to cancel): 2
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.recover.ranqx.com
Error while running apache2ctl graceful.

Thank you

Hi,

Do you mind to tell us whatā€™s the issue?

Thank yyou

sorry i was editing the pre defined template answer. thank youā€¦

Hi,

Please run apachectl configtest and share us the outputs.

Also, since you have deleted the certificate, apache might not run because they canā€™t find those files.
The easiest way to resolve this is to find that SSL virtual host that referred the certificate, and commented the whole virtual host out. After you obtained the certificate successfully, uncomment that virtual host (or delete that if certbot creates another one for you)

Thank you

You may need to select both: "1,2"

output is just:
Syntax OK

I did and this is what I get at: less /var/log/letsencrypt/letsencrypt.log

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/certbot/error_handler.py", line 108, in _call_registered
    self.funcs[-1]()
  File "/usr/lib/python3/dist-packages/certbot/auth_handler.py", line 310, in _cleanup_challenges
    self.auth.cleanup(achalls)
  File "/usr/lib/python3/dist-packages/certbot_apache/configurator.py", line 2150, in cleanup
    self.restart()
  File "/usr/lib/python3/dist-packages/certbot_apache/configurator.py", line 2013, in restart
    self._reload()
  File "/usr/lib/python3/dist-packages/certbot_apache/configurator.py", line 2041, in _reload
    raise errors.MisconfigurationError(error)
certbot.errors.MisconfigurationError: Error while running apache2ctl graceful.
httpd not running, trying to start
Action 'graceful' failed.
The Apache error log may have more information.

When checking the apache log /var/log/apache2/error.log

> [Sun Dec 09 20:43:27.720609 2018] [ssl:emerg] [pid 1330] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/wordpress-error.log for more information
> AH00016: Configuration Failed
> [Sun Dec 09 20:44:56.063370 2018] [ssl:emerg] [pid 2537] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/wordpress-error.log for more information
> AH00016: Configuration Failed
> [Sun Dec 09 20:46:26.855455 2018] [ssl:emerg] [pid 2599] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/wordpress-error.log for more information
> AH00016: Configuration Failed
> [Sun Dec 09 20:46:26.984347 2018] [ssl:emerg] [pid 2606] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/wordpress-error.log for more information
> AH00016: Configuration Failed  

 **then I get this in the customized log _/var/log/apache2/wordpress-error.log_**


> [Sun Dec 09 20:43:27.720065 2018] [ssl:emerg] [pid 1330] AH02572: Failed to configure at least one certificate and key for recover.ranqx.com:443
> [Sun Dec 09 20:43:27.720599 2018] [ssl:emerg] [pid 1330] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
> [Sun Dec 09 20:44:56.063313 2018] [ssl:emerg] [pid 2537] AH02572: Failed to configure at least one certificate and key for recover.ranqx.com:443
> [Sun Dec 09 20:44:56.063364 2018] [ssl:emerg] [pid 2537] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
> [Sun Dec 09 20:46:26.855400 2018] [ssl:emerg] [pid 2599] AH02572: Failed to configure at least one certificate and key for recover.ranqx.com:443
> [Sun Dec 09 20:46:26.855451 2018] [ssl:emerg] [pid 2599] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned
> [Sun Dec 09 20:46:26.984291 2018] [ssl:emerg] [pid 2606] AH02572: Failed to configure at least one certificate and key for recover.ranqx.com:443
> [Sun Dec 09 20:46:26.984342 2018] [ssl:emerg] [pid 2606] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned

Please show the configuration file.

here. I just changed the name of domains and some private info but is the config file.
Config File at /etc/apache2/sites-enabled with a symlink to /etc/apache2/sites-available

<VirtualHost *:80>
>ServerName recover.example.com
>ServerAlias www.recover.example.com

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/wordpress-error.log
	CustomLog ${APACHE_LOG_DIR}/wordpress-access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

<IfModule mod_ssl.c>
	<VirtualHost _default_:443>
		ServerAdmin webmaster@localhost

		DocumentRoot /var/www/wordpress/wordpress

		Redirect /login https://app.example.com/login
		RedirectMatch ^/((au|nz)/asbtestnzltd/asbtestnzltd) https://app.example.com/$1
		RedirectMatch ^/((survey|resetting|register/confirm|hsbc-reports)/.*)$ https://app.example.com/$1
		RedirectMatch ^/(ASBBANK.*)$ https://app.example.com/$1

        <Directory /var/www/wordpress/wordpress>
            Options FollowSymLinks
            AllowOverride All
            DirectoryIndex index.php
            Require all granted
        </Directory> 
		# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
		# error, crit, alert, emerg.
		# It is also possible to configure the loglevel for particular
		# modules, e.g.
		#LogLevel info ssl:warn

		ErrorLog ${APACHE_LOG_DIR}/wordpress-error.log
		CustomLog ${APACHE_LOG_DIR}/wordpress-access.log combined

		# For most configuration files from conf-available/, which are
		# enabled or disabled at a global level, it is possible to
		# include a line for only one particular virtual host. For example the
		# following line enables the CGI configuration for this host only
		# after it has been globally disabled with "a2disconf".
		#Include conf-available/serve-cgi-bin.conf

		#   SSL Engine Switch:
		#   Enable/Disable SSL for this virtual host.
		SSLEngine on

		#   A self-signed (snakeoil) certificate can be created by installing
		#   the ssl-cert package. See
		#   /usr/share/doc/apache2/README.Debian.gz for more info.
		#   If both key and certificate are stored in the same file, only the
		#   SSLCertificateFile directive is needed.
#		SSLCertificateFile	/etc/ssl/certs/example-com.crt
#		SSLCertificateKeyFile /etc/ssl/private/example-com.key
#SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
#Include /etc/letsencrypt/options-ssl-apache.conf


		#   Server Certificate Chain:
		#   Point SSLCertificateChainFile at a file containing the
		#   concatenation of PEM encoded CA certificates which form the
		#   certificate chain for the server certificate. Alternatively
		#   the referenced file can be the same as SSLCertificateFile
		#   when the CA certificates are directly appended to the server
		#   certificate for convinience.
		#SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

		#   Certificate Authority (CA):
		#   Set the CA certificate verification path where to find CA
		#   certificates for client authentication or alternatively one
		#   huge file containing all of them (file must be PEM encoded)
		#   Note: Inside SSLCACertificatePath you need hash symlinks
		#		 to point to the certificate files. Use the provided
		#		 Makefile to update the hash symlinks after changes.
		#SSLCACertificatePath /etc/ssl/certs/
		#SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

		#   Certificate Revocation Lists (CRL):
		#   Set the CA revocation path where to find CA CRLs for client
		#   authentication or alternatively one huge file containing all
		#   of them (file must be PEM encoded)
		#   Note: Inside SSLCARevocationPath you need hash symlinks
		#		 to point to the certificate files. Use the provided
		#		 Makefile to update the hash symlinks after changes.
		#SSLCARevocationPath /etc/apache2/ssl.crl/
		#SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

		#   Client Authentication (Type):
		#   Client certificate verification type and depth.  Types are
		#   none, optional, require and optional_no_ca.  Depth is a
		#   number which specifies how deeply to verify the certificate
		#   issuer chain before deciding the certificate is not valid.
		#SSLVerifyClient require
		#SSLVerifyDepth  10

		#   SSL Engine Options:
		#   Set various options for the SSL engine.
		#   o FakeBasicAuth:
		#	 Translate the client X.509 into a Basic Authorisation.  This means that
		#	 the standard Auth/DBMAuth methods can be used for access control.  The
		#	 user name is the `one line' version of the client's X.509 certificate.
		#	 Note that no password is obtained from the user. Every entry in the user
		#	 file needs this password: `xxj31ZMTZzkVA'.
		#   o ExportCertData:
		#	 This exports two additional environment variables: SSL_CLIENT_CERT and
		#	 SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
		#	 server (always existing) and the client (only existing when client
		#	 authentication is used). This can be used to import the certificates
		#	 into CGI scripts.
		#   o StdEnvVars:
		#	 This exports the standard SSL/TLS related `SSL_*' environment variables.
		#	 Per default this exportation is switched off for performance reasons,
		#	 because the extraction step is an expensive operation and is usually
		#	 useless for serving static content. So one usually enables the
		#	 exportation for CGI and SSI requests only.
		#   o OptRenegotiate:
		#	 This enables optimized SSL connection renegotiation handling when SSL
		#	 directives are used in per-directory context.
		#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
		<FilesMatch "\.(cgi|shtml|phtml|php)$">
				SSLOptions +StdEnvVars
		</FilesMatch>
		<Directory /usr/lib/cgi-bin>
				SSLOptions +StdEnvVars
		</Directory>

		#   SSL Protocol Adjustments:
		#   The safe and default but still SSL/TLS standard compliant shutdown
		#   approach is that mod_ssl sends the close notify alert but doesn't wait for
		#   the close notify alert from client. When you need a different shutdown
		#   approach you can use one of the following variables:
		#   o ssl-unclean-shutdown:
		#	 This forces an unclean shutdown when the connection is closed, i.e. no
		#	 SSL close notify alert is send or allowed to received.  This violates
		#	 the SSL/TLS standard but is needed for some brain-dead browsers. Use
		#	 this when you receive I/O errors because of the standard approach where
		#	 mod_ssl sends the close notify alert.
		#   o ssl-accurate-shutdown:
		#	 This forces an accurate shutdown when the connection is closed, i.e. a
		#	 SSL close notify alert is send and mod_ssl waits for the close notify
		#	 alert of the client. This is 100% SSL/TLS standard compliant, but in
		#	 practice often causes hanging connections with brain-dead browsers. Use
		#	 this only for browsers where you know that their SSL implementation
		#	 works correctly.
		#   Notice: Most problems of broken clients are also related to the HTTP
		#   keep-alive facility, so you usually additionally want to disable
		#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
		#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
		#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
		#   "force-response-1.0" for this.
		# BrowserMatch "MSIE [2-6]" \
		#		nokeepalive ssl-unclean-shutdown \
		#		downgrade-1.0 force-response-1.0
		SSLProtocol -all +TLSv1.1 +TLSv1.2

	</VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

done. is attached in my answer.

The config seems a bit ā€œcomplicatedā€.
Maybe you can try without
--apache
And instead use
--webroot -w /var/www/wordpress/wordpress

But you may also need to create the acme-challenge path:
mkdir /var/www/wordpress/wordpress/.well-known/
mkdir /var/www/wordpress/wordpress/.well-known/acme-challenge/
and place a test file to check from the Internet:
echo "working" > /var/www/wordpress/wordpress/.well-known/acme-challenge/1234
with
http://{your.domain}/.well-known/acme-challenge/1234

1 Like

thanks for your answer. I purged Apache2 by reinstalling it and validating the modules.

What concerns me is that in the past I had already succesfully obtained two certificates:

  1. recover.example.com
  2. www.recover.example.com

I followed some instructions from this community and I removed all certificates.

sudo certbot delete

Now, today Apache was not starting and after disabling SSL module, apache works now. even with the weird configurations. If SSL mod is enabled i can see this error:
error:140A80B1:SSL routines:SSL_CTX_check_private_key:no certificate assigned

By Purging Apache2 certbot was removed too. At the moment I will reinstall certbot and run the following:
sudo certbot --apache certonly -d www.recover.ranqx.com -d recover.ranqx.com

What do you think of that apporach?

I will let you know the details as i am going for a mind break .

This error meant you are trying to do TLS(SSL) without a certificate.
Which makes sense, if you had deleted them all.

Using certonly shifts a lot of the certificate handling onto you.
I would let certbot handle it (if it can).
With either this:
sudo certbot --apache -d www.recover.ranqx.com -d recover.ranqx.com
or this:
sudo certbot --webroot -w /var/www/wordpress/wordpress -d www.recover.ranqx.com -d recover.ranqx.com
[whichever works for you]

Also, I would not chose to have cerbot automatically redirect the http to https for you (you should handle that yourself).

1 Like

As @rg305 pointed out, if you have HTTPS working on your site, the Apache configuration points to particular certificate files, such as files under /etc/letsencrypt/live. If you delete those files with certbot delete without changing your Apache configuration, your Apache configuration will become invalid because it points at nonexistent files.

Ok thanks all. this was my troubleshooting:
PROBLEM= messed up apache config with SSL. www.example.com and example.com not working and browser gives this annoying Certificate issue thing due to bad configuration of the certificate on my side.

PROCEDURE=
purged apache and reinstalled everything
commented the horrible apache.conf mess that I had and left basic settings
re-enabled all mods such as ssl
reinstalled certbot

ran this:
sudo certbot --apache -d www.recover.ranqx.com -d recover.ranqx.com
adapted my apache.conf pointing to the new /etc/letsencrypt/live/www.recover.example.com/fullchain.pem
sudo apachectl configtest
sudo service apache2 restart
sudo systemctl status apache2.service

TESTING=

wget www.recover.example.com
wget recover.example.com
wget https://www.recover.example.com/
wget https://recover.example.com/

OUTCOME=
All is working now thanks
Thanks All

1 Like

Iā€™m happy to hear that it is working.
And alsoā€¦
Happy Birthday!

2 Likes

Thank you. God bless you

1 Like