I have installed apache2 on my laptop, and created a virtual host to work on a site for development. This is working fine. I now need to add a second site, and have come across issues, despite the setup being identical to the first (working) vhost config.
Whenever i access the second site, the request is redirected to https (even if http is defined), and the browser returns a "unable to connect" error page.
http://dev.mysite.co.uk > loads ok
http://dev.mysite2.co.uk > redirects to https://dev.mysite2.co.uk, and "unable to connect" message
I have looked into the problem for the past few evenings and tried many suggestions, including www/ dir permissions, but none have worked.
Site 1 config, located in /etc/apache2/sites-available (working without issue):
<VirtualHost *:80> ServerName dev.mysite1.co.uk DocumentRoot /var/www/mysite1/public_html <Directory /var/www/mysite1/public_html> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/mysite1.co.uk-error.log CustomLog ${APACHE_LOG_DIR}/mysite1.co.uk-access.log combined </VirtualHost>
Site 2 config, located in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerName dev.mysite2.co.uk
DocumentRoot /var/www/mysite2/public_html
<Directory /var/www/mysite2/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysite2.co.uk-error.log
CustomLog ${APACHE_LOG_DIR}/mysite2.co.uk-access.log combined
</VirtualHost>
…both enabled via a2ensite.
/etc/hosts file:
127.0.0.1 localhost
127.0.0.1 dev.site2.co.uk
127.0.0.1 dev.site1.co.uk
127.0.0.1 phpmyadmin
127.0.1.1 mymachine
# The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Output of apachectl configtest:
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
Syntax OK
(i have previously set "ServerName localhost" in apache2.conf, which removed the first FQDN message, but didn’t affect the issue i am having). Both have symlinks to the vhost confgs in /etc/apache2/sites-enabled. Apache2.conf is standard / no default to standard installation. Browser extensions disabled / same result in different browsers.
Output of ls -ld /var/www/site1:
drwxrwxrwx 10 me me 4096 Jan 15 20:50 /var/www/site1
Output of ls -ld /var/www/site2:
drwxrwxr-x 9 me www-data 4096 May 17 22:45 /var/www/site2
Is the difference in site2 having www-data permissions? Which should be apache-user readable?
No difference made by chown -R 755 /var/www
Also realised that http://localhost is also redirecting to https://localhost and an "unable to connect" message.
http://localhost/phpmyadmin works fine.
Output of 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 dev.site1.co.uk (/etc/apache2/sites-enabled/site1.conf:1)
port 80 namevhost dev.site1.co.uk (/etc/apache2/sites-enabled/site1.conf:1)
port 80 namevhost dev.site2.co.uk (/etc/apache2/sites-enabled/site2.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 mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: 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
2
Answers
This problem could be related to 301 redirect caching. E.g. In the past you’ve set a
301
redirect (Moved Permanently ) towardshttps
and now it is cached in the browser(s).If this is the case, the following links may help find a solution:
Note: you may first try with browsers, that did not use the specific domain in the past, or
curl/wget
and check whether they face the same problem. If not, most probably it is the caching problem.Other possible causes:
Note about
dev.mysite.co.uk
: You mention that it works ok, but I do not see any configuration about that domain. Is it a typo?Your question mentions 5 different hostnames.
The apache configs don’t match the apachectl output and the /etc/hosts contents.
So, you edited something.
The below is conjecture, as it isn’t known which parts are edited.
Could this be happening:
For the first site, all is well, but for the second, your request does not match the config or hosts-entry, so the browser tries https and fails because dev.site2.co.uk and dev.mysite2.co.uk do not exist in dns.
You could look in the logfiles to see if this is the case: If there are no log-entries for [my]site2, the hosts-entry is a likely culprit.