CertBot unable to install certificate on fresh apache2 installation

I just put a fresh install of apache2 onto my DigitalOcean server, and for some reason CertBot can't automatically install the certificates. All apache2 config files are completely default. What can I do? Should I try to manually install the certificates, or is there something else I need to do?

My domain is: http://www.2darkpark.net

I ran this command: sudo certbot --apache

It produced this output:

Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.

AH00526: Syntax error on line 69 of /etc/apache2/sites-enabled/000-default-le-ssl.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Rolling back to previous server configuration...
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.

AH00526: Syntax error on line 69 of /etc/apache2/sites-enabled/000-default-le-ssl.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration


IMPORTANT NOTES:
 - We were unable to install your certificate, however, we
   successfully restored your server to its prior configuration.

My web server is (include version): Apache/2.4.41 (Ubuntu)

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

My hosting provider, if applicable, is: DigitalOcean

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 1.13.0

2 Likes

Welcome to the Let's Encrypt Community, Nat :slightly_smiling_face:

What is the output of:

sudo apachectl -S

What are the contents of:

/etc/apache2/sites-available/000-default.conf

Please put three backticks ``` on the lines above and below each output.

Example:

```
output
```

3 Likes

thank you for your response!

the output of sudo apachectl -S is

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   www.2darkpark.net (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

the contents of /etc/apache2/sites-available/000-default.conf are:

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	ServerName www.2darkpark.net
	
	ServerAdmin nat@2darkpark.net
	DocumentRoot /var/www/html

	# 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}/error.log
	CustomLog ${APACHE_LOG_DIR}/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>

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

Let's have a look at this file:

3 Likes
$ cat /etc/apache2/sites-available/000-default-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com
	
	ServerName www.2darkpark.net
	ServerAdmin nat@2darkpark.net
	DocumentRoot /var/www/html/

	# 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}/error.log
	CustomLog ${APACHE_LOG_DIR}/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


ServerAlias www.2darkpark.net
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.2darkpark.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.2darkpark.net/privkey.pem
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com
	
	ServerName www.2darkpark.net
	ServerAdmin nat@2darkpark.net
	DocumentRoot /var/www/html/

	# 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}/error.log
	CustomLog ${APACHE_LOG_DIR}/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
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

# RewriteCond %{SERVER_NAME} =www.2darkpark.net [OR]
# RewriteCond %{SERVER_NAME} =www.2darkpark.net
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


</VirtualHost>
</IfModule>
2 Likes

Firstly, run these:

sudo a2dissite *.conf

sudo rm /etc/apache2/sites-enabled/*.*

sudo rm /etc/apache2/sites-available/*.*

Secondly, create /etc/apache2/sites-available/2darkpark.net.conf with a text editor and put the following into it:

<VirtualHost *:80>
ServerName 2darkpark.net
ServerAlias www.2darkpark.net
ServerAdmin nat@2darkpark.net
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Thirdly, run these:

sudo a2ensite 2darkpark.net.conf

sudo apachectl -k graceful

sudo certbot --apache -d "2darkpark.net,www.2darkpark.net" --keep
2 Likes

Alright, certbot has successfully installed the cert but now I can't connect to the website? When I try to navigate to the URL, it just loads forever, but if I enter the IP address in my browser, it connects - albeit over http.

1 Like

Hi,

From my port test (using portqry on Windows), your port 443 seems to be filtered.
Can you double check on your DigitalOcean firewall as well as droplet firewall to ensure you opened port 443 on both?

P.S. You can view your DigitalOcean firewall at https://cloud.digitalocean.com/networking/firewalls

Thank you

2 Likes

Whoops! I opened port 443 on my firewall and now I can access the site over https, but it defaults to http. How do I force https?

1 Like

Certbot should have installed an http to https redirect. Did you choose not to allow the redirect somehow?

What are the current contents of:

/etc/apache2/sites-available/2darkpark.net.conf

2 Likes
$ cat /etc/apache2/sites-available/2darkpark.net.conf
<VirtualHost *:80>
	ServerName 2darkpark.net
	ServerAlias www.2darkpark.net
	ServerAdmin nat@2darkpark.net
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.2darkpark.net [OR]
RewriteCond %{SERVER_NAME} =2darkpark.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
1 Like

Try running this real quick:

sudo apachectl -k graceful

Let me know once you have.

2 Likes

Just did, doesn't seem to have done much.

1 Like

Let's simplify...

In /etc/apache2/sites-available/2darkpark.net.conf replace all of these lines:

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.2darkpark.net [OR]
RewriteCond %{SERVER_NAME} =2darkpark.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

with this one line:

Redirect permanent "/" "https://www.2darkpark.net/"

Then run:

sudo apachectl -k graceful

edit:
I fixed the redirect line to have your domain name.

1 Like

That hasn't done anything either, sorry. Running sudo apachectl -k graceful returns the output

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

but I don't think that has anything to do with the problem.

1 Like

That error/warning is normal. I know how weird that sounds. :upside_down_face:

2 Likes

Alrighty...

sudo ls -la /etc/apache2/sites-available

sudo ls -la /etc/apache2/sites-enabled
2 Likes
$ sudo ls -la /etc/apache2/sites-available
total 16
drwxr-xr-x 2 root root 4096 Apr  4 06:08 .
drwxr-xr-x 8 root root 4096 Apr  4 02:50 ..
-rw-r--r-- 1 root root 1089 Apr  4 02:50 2darkpark.net-le-ssl.conf
-rw-r--r-- 1 root root  483 Apr  4 06:08 2darkpark.ne`t.conf
$ sudo ls -la /etc/apache2/sites-enabled
total 8
drwxr-xr-x 2 root root 4096 Apr  4 05:39 .
drwxr-xr-x 8 root root 4096 Apr  4 02:50 ..
lrwxrwxrwx 1 root root   54 Apr  4 02:50 2darkpark.net-le-ssl.conf -> /etc/apache2/sites-available/2darkpark.net-le-ssl.conf
lrwxrwxrwx 1 root root   37 Apr  4 02:35 2darkpark.net.conf -> ../sites-available/2darkpark.net.conf
1 Like

Is that backquote actually in the filename!?

1 Like

oh goodness I hope not

1 Like