2

I am setting up my laptop for single-user development of multiple sites using the LAMP stack on Ubuntu 16.10 with virtual hosts for the different sites, and name-based virtual hosts. I have tried various combinations of config settings, but I cannot load a site from the Browser, I get "the requested URL was not found on this server." Here are relevant code snippets from relevant config files:

Ports.conf:

Listen 8000

apache2.conf:

NameVirtualHost *:8000
ServerName localhost
...

.../sites-enabled/000-default.conf:

<VirtualHost *:8000>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
...

.../sites-enabled/abc.conf:

<VirtualHost *:8000>
ServerName abc
ServerAdmin [email protected]
ServerAlias www.abc.com abc.com
DocumentRoot /var/www/abc

.../sites-enabled/pbnat.conf:

<VirtualHost *:8000>
ServerName pbnat
ServerAdmin [email protected]
ServerAlias pbnat.com pbn.com
DocumentRoot /var/www/pbnat/public
...

/etc/hosts

127.0.0.1   localhost
127.0.1.1   Lenovo-y2-11
127.0.0.1   abc
127.0.0.1   pbnat

Dir Struct:

/var/www/
   |-- abc/
       |- index.html
   |-- html/
       |- index.html
   |-- pbnat/
       |-- public/
           |- index.html

Permissions on /var/www/:

drwxr-xr-x 2 www-data julie 4096 Jan  8 16:53 abc
drwxrwxr-x 2 root     root  4096 Dec 31 00:02 html
drwxrwxr-x 3 www-data pbnat 4096 Jan  6 22:32 pbnat

Permissions on /var/www/abc/:

-rw-r--r-- 1 www-data julie 139 Jan  8 16:53 index.html

Permissions on /var/www/html/:

-rwxrwxr-x 1 root root 11321 Dec 31 00:02 index.html

Permissions on /var/www/pbnat/:

drwxrwxr-x 2 www-data pbnat 4096 Jan  7 00:00 public

Browser URL tests and results:

file:///var/www/abc/index.html - Success! The abc virtual host is working!

file:///var/www/pbnat/public/index.html - Success! The pbnat virtual host is working!

localhost – site can’t be reached; localhost refused to connect.

localhost:8000 – Apache2 Ubuntu default page

localhost:8000/abc - The requested URL /abc was not found on this server.

localhost:8000/abc.com - The requested URL /abc.com was not found on this server.

  • then I changed the IP to 127.0.0.2 in hosts file for the new sites but left localhost as 127.0.0.1 and tried:

127.0.0.2:8000 - Apache2 Ubuntu default page

127.0.0.2:8000/abc – The requested URL /abc was not found on this server.

Error log shows nothing unusual, Access log shows HTTP status code of 404, along with a second code of 495 or 496; also it lists 127.0.0.1 in the first column of the log even if I enter 127.0.0.2:8000/abc

Been going at this quite some time. Help much appreciated.

8
  • I will recommend you to follow it. Maybe it can help you digitalocean.com/community/tutorials/… Commented Jan 9, 2017 at 2:35
  • @Abbas I did actually heavily reference that tutorial while doing this; I only get the "Success" page by opening the local html file in the browser, can't open it through apache using an IP address or server name/host name. Commented Jan 9, 2017 at 2:44
  • There are two things which i notice. There is no sites-available in your question. And second is Your ServerName should be the virtual host name. Like in your case it should be ServerName abc.com Commented Jan 9, 2017 at 2:54
  • <VirtualHost *:80> ServerName magento1local.com ServerAlias www.magento1local.com ServerAdmin [email protected] DocumentRoot /home/abbas/www/magento1local.com CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/home/abbas/www/magento1local.com"> Options Indexes FollowSymLinks MultiViews # changed from None to All AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> Above is one of my host. Commented Jan 9, 2017 at 2:55
  • @Abbas I am using a2ensite to create the links in sites-enabled from the files in sites-available, just didn't wamt to further clutter my question. And, I believe that the server names I provided in the VH blocks match the server names in the hosts file, the .com part is not really necessary in these config directives but I do include them as aliases for completeness. I will yry the Directory block lines to see ehat effect thst has. Can you show me your hosts file? Commented Jan 9, 2017 at 4:43

1 Answer 1

2

The problem was based in how the URL is entered in the browser. It should be: abc:8000 Not: localhost:8000/abc

Sign up to request clarification or add additional context in comments.

1 Comment

How can we access the virtual hosts from a host machine with apache2 running on Ubuntu-server on a VM-guest (say, VirtualBox)? I have the same situation as above, except that I am not able to access it from the host. I can access the default website with the localhost and port, but not any other websites...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.