1

I think I have set it up properly but I am just getting a "refused to connect." message

To start with it is just simple http.

My domain is good-health.ml

So I set up this in /etc/apache2/sites-available

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName good-health.ml
    ServerAlias www.good-health.ml
    DocumentRoot /var/www/good-health.ml

    <Directory /var/www/good-health.ml>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/good-health/error.log
    CustomLog /var/log/apache2/good-health/access.log combined
</VirtualHost>

I created the sub-directory for the logs

I created this file at /var/www/good-health.ml/index.html

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Welcome to Good-Health</title>
  </head>
  <body>
    <h1>Success! Good-Health!</h1>
  </body>
</html>

I ran apachectl configtest

Syntax OK

I ran :

a2ensite good-health.ml
systemctl reload apache2
systemctl restart apache2

I checked ... service apache2 status

* apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-05-05 23:07:17 BST; 42min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 2590109 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)    Main PID: 2590131 (apache2)
      Tasks: 55 (limit: 19071)
     Memory: 8.6M
     CGroup: /system.slice/apache2.service
             |-2590131 /usr/sbin/apache2 -k start
             |-2590132 /usr/sbin/apache2 -k start
             `-2590133 /usr/sbin/apache2 -k start

May 05 23:07:17 Ubuntu20 systemd[1]: Starting The Apache HTTP
Server... May 05 23:07:17 Ubuntu20 systemd[1]: Started The Apache HTTP
Server.

Everything should be OK but I get this ...

Good-Health

Obviously I have internet, I'm posting this.

I can ping good-health.ml. What have I done wrong?

Thanks

Ahh - OK I think I have found the problem

When I enter "good-health.ml" into my chrome browser it seems to automatically put an https:// in front.

The server doesn't connect because it only serves on port 80

I don't know why my browser is doing that.

This is a new Apache2 install To use HTTPS I have to run:

sudo a2enmod ssl

and then up a good-health.ml-ssl.conf

Is that correct?

1 Answer 1

1

Your HTTP site does work:

$ curl http://good-health.ml
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Welcome to Good-Health</title>
  </head>
  <body>
    <h1>Success! Good-Health!</h1>
  </body>
</html>

As for why your browser is requesting the HTTPS site, there are two possibilities:

  • The domain had HTTPS Strict Transport Security (HSTS) enabled. Once HSTS is set up for a domain, browsers will always try HTTPS and ignore HTTP. Some top level domains (like .dev) have HSTS enabled for all domain names.

    However, I don't see any evidence that HSTS has ever been enabled for your domain, nor does .ml appear to be on the HSTS preload list, which would be the mechanism for enabling HSTS for all domains under it.

  • Your browser may be configured for HTTPS-Only. All major browsers now have settings to only use HTTPS sites. See How to Enable HTTPS-Only Mode in Chrome, Firefox, Edge, and Safari

You will definitely want to set up HTTPS for your domain. I consider enabling HTTPS to be mandatory for any domain these days. Many browsers won't be able to use your site without it.

Apache will need mod_ssl enabled and you will need a virtual host for your site on port 443. I usually put my HTTP and HTTPS configuration for sites into the same file. I'd recommend having /etc/apache2/sites-available/good-health.ml.conf with:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName good-health.ml
    ServerAlias www.good-health.ml
    
    Redirect / https://good-health.ml/

    ErrorLog /var/log/apache2/good-health/error.log
    CustomLog /var/log/apache2/good-health/access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName good-health.ml
    ServerAlias www.good-health.ml
    DocumentRoot /var/www/good-health.ml

    <Directory /var/www/good-health.ml>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/good-health/error.log
    CustomLog /var/log/apache2/good-health/access.log combined

    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3
    SSLCipherSuite ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL
    SSLCertificateFile /etc/letsencrypt/live/good-health.ml/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/good-health.ml/privkey.pem
</VirtualHost>

Which assumes that you get your certificates for HTTPS from Lets Encrypt. Their certificates are free and widely used, but they require some work to set them up on your own server. They expire quickly, so you need an automated process to renew them. Since you are using freenom as your DNS host, it would probably be best to use the DNS validation method with the freenom plugin for certbot to obtain LetsEncrypt certificates for your site.

8
  • Thanks for your detailed answer. I didn't know I could put both :80 and :443 in the same file, but it makes sense as all the .conf files are put together and read. I guess I could put ALL my domains into one .conf file. ( like in the old days ) it would make editing them faster.
    – Dave
    Commented May 6, 2022 at 8:22
  • I have used Lets Encrypt before. I am now wanting to use CloudFlare as that is free as well. I need to install their Origin certificate and Private Key to make it encrypted from server, through CF and on to client. I had difficulty with it yesterday, so I removed Apache2 and re-installed it. I hadn't run enabled mod_ssl - I think that was the problem.
    – Dave
    Commented May 6, 2022 at 8:31
  • Yup, Cloudflare will work too. The only thing that would be different would be the path to certificate files. And you'll need to change your NS records at your DNS registrar to point to Cloudflare using the values that Cloudflare gives you. Commented May 6, 2022 at 8:33
  • To enable mod_ssl do I need to run a2enmod ssl or is there anything else I need to do ? I am using an Ubuntu 20.04. Have you used CloudFlare at all?
    – Dave
    Commented May 6, 2022 at 8:33
  • You will need to reload apache config as well. sudo service apache2 reload or possibly fully restart it sudo service apache2 restart. You'll also need to do that every time you change other configuration such as adding or changing the conf for your site. Commented May 6, 2022 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.