5

I've got a Linode configured as a Ubuntu 10.04.2 web server with Apache 2.2.14.

I have a total of 4 sites, all defined under /etc/apache2/sites-available as virtual hosts. All sites are almost identical clones for configuration. And all sites but my last work successfully.

default:      (www.)exampleadnetwork.com
              (www.)example.com
          reseller.example.com
trouble:   client1.example.com

I keep getting this page when I visit the client1.example.com site:

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

In my ports.conf file I have the NameVirtualHost correctly set to my IP address on port 80.

If I access the "www.sub.example.com" alias the site works! If I access it without the www I see the "It Works" excerpt posted above. Even apache2ctl -S shows that my vhost file parses correctly and is added to the mix.

My vhost configuration file is as follows:

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    ServerName  client1.example.com
    ServerAlias client1.example.com www.client1.example.com
    DocumentRoot    /srv/www/client1.example.com/public_html/
    ErrorLog    /srv/www/client1.example.com/logs/error.log
    CustomLog   /srv/www/client1.example.com/logs/access.log combined

    <directory /srv/www/client1.example.com/public_html/>
        Options -Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </directory>
</VirtualHost>

The other sites are variations of:

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    ServerName  example.com
    ServerAlias example.com www.example.com
    DocumentRoot    /srv/www/example.com/public_html/
    ErrorLog    /srv/www/example.com/logs/error.log
    CustomLog   /srv/www/example.com/logs/access.log combined
</VirtualHost>

The only site the differs is the other subdomain:

<VirtualHost 127.0.0.1:80>
    ServerAdmin [email protected]
    ServerName  reseller.example.com
    ServerAlias reseller.example.com
    DocumentRoot    /srv/www/reseller.example.com/public_html/
    ErrorLog    /srv/www/reseller.example.com/logs/error.log
    CustomLog   /srv/www/reseller.example.com/logs/access.log combined
</VirtualHost>

Filenames are the FQDN without the www. prefix.

I've followed this advice, but still cannot access subdomain properly.

9
  • 1
    Your config only shows us one of the 3 sites where are the other's configured and how?
    – user9517
    Jul 18, 2011 at 20:43
  • They're also configured under /etc/apache2/sites-available in nearly identical ways. The only thing that changes for each of these is the server name to the domain name(s) it handles, and the physical path.
    – Robert K
    Jul 18, 2011 at 20:47
  • The contents of the files and the filenames are important.
    – user9517
    Jul 18, 2011 at 20:49
  • Is there anything relevant in your error and access logs ?
    – user9517
    Jul 18, 2011 at 21:14
  • 1
    You mention sites-available, but that directory doesn't really matter much, what is listed in sites-enabled? Did you run a2ensite to create the symlink from enabled -> available?
    – Zoredache
    Jul 19, 2011 at 0:11

6 Answers 6

1

I experienced the exact same problem and eventually what solved the problem was when I disabled the default site in apache by unlinking it from sites-enabled:

sudo unlink /etc/apache2/sites-enabled/000-default

After doing this, all my sites displayed correctly. I see this question is quite old, but hope this can help someone else out there.

2
  • I did this, to no success.
    – Robert K
    Sep 13, 2012 at 13:42
  • I used a2dissite and reloaded apache - and it worked. It was only on my main virtual host it was doing this... My guess was that the 000-default was the first virtual host to match so it never read the one I wanted it to use.
    – amurrell
    May 17, 2014 at 16:28
1

The solutions of the other posters will do it.

You "it Works" is shown, becase all your Virtuall Host match to localhost. And if you call "client1.example.com" apache will skipp the localhost Vhosts and if there is no matching Vhost, it will use se default config.

Do what the other posters told (change your vitial hosts to <VirtualHost *:80> of <VirtualHost *> of change your default vhost to the Document root you like.

Don`t forget: even if you define your Vhosts correctly, the server will call the default site if some one requests your server without a hostname (e.g. via ip address).

0

Try it without having a duplicate entry in ServerName and ServerAlias.

For example:

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName  sub.example.com
ServerAlias www.sub.example.com
DocumentRoot    /srv/www/sub.example.com/public_html/
ErrorLog    /srv/www/sub.example.com/logs/error.log
CustomLog   /srv/www/sub.example.com/logs/access.log combined

<directory /srv/www/sub.example.com/public_html/>
    Options -Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</directory>

1
  • Tried that. I can still access both addresses, but only the one with the www. prefix operates correctly.
    – Robert K
    Jul 18, 2011 at 21:01
0

Some suggestions:

  • Change the <VirtualHost 127.0.0.1:80> for <VirtualHost *:80>
  • Did you place the NameVirtualHost *:80 configuration?
  • Place an index.html file under each DocumentRoot, obviously each with a different message to identify where are you accessing
  • Try accessing from localhost and if it's possible try from another location
8
  • In FILO order: Localhost access is identical to remote; no need for an index file, all are distinct (but the one gives a "It works" page instead of an Install Wordpress page; transitioning to *:80 from the IP address produces the same result.
    – Robert K
    Jul 18, 2011 at 21:48
  • Did you place "NameVirtualHost *:80"?
    – ghm1014
    Jul 18, 2011 at 21:51
  • Yes. It was already there, I just changed the IP to a *.
    – Robert K
    Jul 18, 2011 at 21:58
  • I just copied your configuration in my desktop and it works fine. There must be something else, some other config or maybe a browser problem? Cache or something?
    – ghm1014
    Jul 18, 2011 at 22:21
  • Tried with FF, Chrome, and cURL w/the same result. Must be something else in my config files that is doing it.
    – Robert K
    Jul 18, 2011 at 22:30
0

Have you checked the DNS resolution of your sites?

(www.)sub.example.com both resolves to the same machine (even if different addresses)?

Check the logs, both of them, to see if all your access are hitting the proper server (configuration), or if they are hitting the default, since the "It Works!" is the default page, of the default configuration.

If they are hitting the default, you have to identify why is that so... what are the differences between the configurations. Try changing the IP, as suggested before, since Apache will bind the configuration to the specific IP address stated on the VirtualHost directive.

0

Your configs are not setup properly for NameVirualHost. Get rid of the the 127.0.0.1 and make that a wildcard of *. When you explicitly set 127.0.0.1 that will bind all connections on your machine to that config. NameVirualHost needs a wildcard of *:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName  client1.example.com
    ServerAlias client1.example.com www.client1.example.com
    DocumentRoot    /srv/www/client1.example.com/public_html/
    ErrorLog    /srv/www/client1.example.com/logs/error.log
    CustomLog   /srv/www/client1.example.com/logs/access.log combined

    <directory /srv/www/client1.example.com/public_html/>
        Options -Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </directory>
</VirtualHost>
The other sites are variations of:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName  example.com
    ServerAlias example.com www.example.com
    DocumentRoot    /srv/www/example.com/public_html/
    ErrorLog    /srv/www/example.com/logs/error.log
    CustomLog   /srv/www/example.com/logs/access.log combined
</VirtualHost>
The only site the differs is the other subdomain:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName  reseller.example.com
    ServerAlias reseller.example.com
    DocumentRoot    /srv/www/reseller.example.com/public_html/
    ErrorLog    /srv/www/reseller.example.com/logs/error.log
    CustomLog   /srv/www/reseller.example.com/logs/access.log combined
</VirtualHost>

Also, make sure that NameVirtualHost is set as follows. On my setup under Ubuntu you will see that line in this file: /etc/apache2/ports.conf

NameVirtualHost *:80
Listen 80

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .