Question

I downloaded apache2.2.22 src from http://httpd.apache.org/download.cgi and made the installation. The installation works fine. But the problem arises when I try adding vhosts. I added 2 virtual hosts 1. localhost 2. someother.localhost Both point to different document roots, but resolve to the doc root of the first virtualhost.

hereis my vhost file,

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/webserver/htdocs"
    ServerName localhost
    ErrorLog "logs/localhost-error_log"
    CustomLog "logs/localhost-access_log" common
</VirtualHost>
<Directory /home/sourabhn/somepath>
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/home/sourabhn/somepath"
    ServerName someother.localhost
    ErrorLog "logs/someother-localhost-error_log"
    CustomLog "logs/someother-localhost-access_log" common
</VirtualHost>

I have made the appropriate entry in the hosts file. I am running a Ubuntu 11.10 machine. Please get back with your valuable suggestions

Was it helpful?

Solution

Right away I noticed a difference between your file and the one I cobbled together from net tutorials like this from bobpeers. I've added within the virtual host block the <Directory> block.

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/
ServerName xtiansimonslaptop.local
    <Directory "/var/www/">
        Allow from all
        Options +Includes +Indexes +FollowSymLinks
        AllowOverride all
    </Directory>
</VirtualHost>

I'm working on Drupal and just so I can get a name resolved to the Drupal directory, it will take care of the rest. In the Drupal install I have several projects each with their own domain name set up in one Drupal installtion. Below is the example of a Drupal site named hello.local, and another of my Drupal sites could be cheese.local. Both pointing to the same Directory.

<VirtualHost *:80>
    DocumentRoot /var/www/php/drupal7
    ServerName hello.local
#   ServerAlias *.hello.local
        <Directory "/var/www/php/drupal7">
            Allow from all
            Options +Includes +Indexes +FollowSymLinks
            AllowOverride all
        </Directory>
</VirtualHost>

Right now its working save for the commented line ServerAlias. Which brings up another point I learned about setting up vHosts. The /etc/hosts file is important to get set up properly.

In the example by bobpeers you'll see their hosts entry example,

ServerName bobpeers.live
ServerName bobpeers.dev

I would expect the reverse name live.bobpeers.local to be a clearer example of a server name. And this is the thing--I find there is inconsistency in examples. Some examples simply do not use key terms like .local or follow the generic signature sub-domain.domaon.com. Copying one persons non-normal example you may think the above ServerName references two virtual hosts, live.local and dev.local. For all I know, maybe they do!

One more thing about vHosts. The man page shows this,

   127.0.0.1       localhost
   192.168.1.10    foo.mydomain.org       foo
   192.168.1.13    bar.mydomain.org       bar

What works for my localhost sandbox is this,

   127.0.0.1    localhost
   127.0.0.1    mydomain.local           mydomain
   127.0.0.1    foo.mydomain.local       foo
   127.0.0.1    bar.mydomain.local       bar

Which seems correct since name based is supposed to sort it all out, and not this 192.168.1.x IP Mask nonsense. (^_^)

OTHER TIPS

My advice : Declare a "global" ServerName and a global DocumentRoot, Then use only the core directive ServerAlias in your vhost http://httpd.apache.org/docs/2.0/mod/core.html#serveralias.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top