问题原文
原帖链接 · Dave · CC BY-SA 4.0
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 omitted]
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 ...
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?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 4.0
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
.mlappear 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 omitted]
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 omitted]
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
