"This site can't be reached" when using virtual host
I'm trying to set up Apache2 server. Installation and configuration seemed to go well, but when I try to go to my custom web URL I get "This site can't be reached" error. I've tried setting config file up through this answer - Forbidden 403 error when trying to access Apache 2.4.7 web server in browser .
My hosts file looks like this:
127.0.0.1 localhost
127.0.0.1 justtestingthis
127.0.1.1 Hacker
# The following lines are desirable for IPv6 capable hosts
...
My apache2/sites-available/http.justtestingthis.conf
file looks like this:
<VirtualHost 127.0.0.1:80>
ServerAdmin [email protected]
ServerName justtestingthis.com
ServerAlias www.justtestingthis.com
DocumentRoot /home/donatas/Desktop/Projects/justtestingthis/dist/src
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/donatas/Desktop/Projects/justtestingthis/dist/src>
# Allow .htaccess
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I've also created a link of this file in apache2/sites-enabled
using sudo a2ensite http.justtestingthis.conf
.
When I'm accessing the website by just typing in http://localhost my website is being found sucessfully, but when I'm trying to access it through justtestingthis.com or www.justtestingthis.com I'm getting the "This site can't be reached error"...
What am I doing wrong?
The reason why your browser cannot open the justtestingthis.com
page is that there is no alias pointing to where it is supposed to go. You have in your /etc/hosts
file only 127.0.0.1 justtestingthis
, where that is just the name. The browser has no idea where the name with .com
is since it is not specified.
To fix this, change the line in your /etc/hosts
to:
127.0.0.1 www.justtestingthis.com
This should now alias justtestingthis.com
to the localhost
or 127.0.0.1
in your web browser to your Apache page. It will also open with justtestingthis.com
without the www.
Hope this helps!