3

This is exactly what I have set up right now:

cd /var/www
mkdir -p test
cd /var/www/test
sudo nano index.html
cd /etc/apache2/sites-available
sudo nano test.conf
<VirtualHost *:80>
    ServerName localhost223.com
    DocumentRoot /var/www/test
</VirtualHost>
$sudo a2ensite test.conf
$sudo service apache2 reload

I can access my page like this:file:///var/www/test/index.html in web browser.

<html>
    <h1>
         here
    </h1>
</html>

But I cannot do access: http://localhost223.com

I get the error: Could not resolve host

How to resolve this issue?

  • 1
    Did you put 127.0.0.1 localhost223.com in the /etc/hosts file? – George Udosen Aug 23 '17 at 20:56
  • I shouldn't need to but I will try that aswell, I have tried 127.0.1.2 localhost223.com but that just returns the default apache page. – DR. Palson_PH.d Aug 23 '17 at 21:50
  • @George just did "127.0.0.1 localhost223.com" in /etc/hosts file. Did nothing but return the default localhost page. – DR. Palson_PH.d Aug 23 '17 at 21:54
4

As @George said, while there is no FQDN that points to your server's IP, you need to bind the domain name with the loopback interface - 127.0.0.1, through the next line in the /etc/hosts file:

127.0.0.1 localhost223.com

Then edit /etc/apache2/sites-available/test.conf in this way:

<VirtualHost *:80>

        ServerName localhost223.com
        DocumentRoot /var/www/test

        <Directory /var/www/test>
                Options None FollowSymLinks
                # Enable .htaccess Overrides:
                AllowOverride All
                DirectoryIndex index.html index.php
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>

</VirtualHost>

Don't forgot to sudo a2ensite test.conf, then restart the web server:

  • Ubuntu 14.04: sudo service apache2 restart

  • Ubuntu 16.04: sudo systemctl restart apache2.service

Try to access your page through the browser.

|improve this answer|||||
  • U don't know how long I have been trying to get this to work! Thank you! Finally it works! – DR. Palson_PH.d Aug 24 '17 at 20:14
  • Happy to help, @DR.Palson_PH.d! – pa4080 Aug 24 '17 at 21:00
  • This works for me when I have access localhost223.com in my ubuntu VM using a web browser. But when I access localhost223.com on my windows machine (I use port forwarding to access) it does not work. I can access localhost fine from outside my VM using port forwarding, but I get server not found error when I try localhost223.com. Any ideas? – DR. Palson_PH.d Sep 1 '17 at 19:40
  • 1
    @DR.Palson_PH.d : Yes I have an idea :) You should add this line: <ubuntu-virtual-lan-ip> localhost223.com into your c:\Windows\System32\Drivers\etc\hosts file. For more detailed answer, please, check here. – pa4080 Sep 1 '17 at 21:58
  • 1
    And maybe this answer is also good example. – pa4080 Sep 1 '17 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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