I have setup http redirect to https in my enabled site cloud.conf
so recently I enabled site 000-default
using sudo a2ensite 000-default
now this enabled my 000-default
site and it was opening the expected document root with no http to https redirect as I didn't had any in 000-default.
But then when I enabled back the site cloud sudo a2ensite cloud
it did enabled my https site which opens expected site cloud but if I open http site it neither redirect automatically to https but also open the 000-default website in http mode.
First of when I have enabled site cloud why is it still opening old site in http mode and not redirecting?
UPDATE
$ apachectl -S
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 is a NameVirtualHost
default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost 192.168.1.3 (/etc/apache2/sites-enabled/cloud.conf:1)
*:443 is a NameVirtualHost
default server 192.168.1.3 (/etc/apache2/sites-enabled/cloud.conf:10)
port 443 namevhost 192.168.1.3 (/etc/apache2/sites-enabled/cloud.conf:10)
port 443 namevhost 192.168.1.3 (/etc/apache2/sites-enabled/cloud.conf:30)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
Now I am wondering how can 2 sites be enabled at port 80
So, there is your problem. You have two http vhosts defined one with
ServerName
127.0.0.1 and one with192.168.1.3
. This means any HTTP request that doesn't use 192.168.1.3 in the address bar will land on the first virtual host (with name 127.0.0.1).Note is doesn't matter that this looks like it should be localhost only, that's just it's name. It's a
*:80
virtual host and so is available on any network interface on the machine.You have two HTTPS virtual hosts in
/etc/apache2/sites-enabled/cloud.conf
both with the sameServerName
(192.168.1.30). Only the first one, the default, will ever receive requests.The way named based virtual hosts works is that for any ip/port combination Apache will try to match the
Host
HTTP header against theServerName
orServerAlias
directives. The first virtual host to match receives the request. If no match is found, then the first one listed receives the request.The
Host
HTTP header defaults to the part of the URL between the scheme (thats the http:// or https:// normally) and the URI path (the bit from the next '/' onward).