Ubuntu – virtual host settings fail on multiple sites

apache-2.2localhostUbuntu

Edited (again): I thought that an apache2 installation on my ubuntu os (personal) would enable me to "host" websites internally – without going onto the web. I am realizing now that the two domains that "work" are actually registered domain names, the other two are names that I intend to register later when I go live. But disconnecting to the Internet stops even the first two domains from working – though I know them to be pulling their files from the localhost.mysitename.com . What's happening here? I'm now reading up on etc/host and etc/host.conf and etc/nsswitch.conf – am I heading in the right direction?

I re-wrote this questions with more info. The problem persists. Thanks:

How in the world can you thoroughly read the apache docs on vHost configuring, try virtually every concoction and still have the initial scenario where the first two vHosts and directories work great and then every one after comes up bad. "Bad Request" "Server Not Found."

Here's the basic vHost file (in /etc/apache2/sites-available), replicated exactly 4 times over with only the "mysitename1" changing, its DocumentRoot and its Directory changing. BTW, this version is using the localhost IP (127.0.0.1) but I've used *:80 with the exact same results.

<VirtualHost 127.0.0.1>
 ServerAdmin xx@yyyyy.com
 ServerName localhost.mysitename1.com

 DocumentRoot /home/folder/folder/folder/folder
 <Directory />
  Options FollowSymLinks
  AllowOverride All
 </Directory>
 <Directory /home/folder/folder/folder/folder>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog "path to this site's error.log"

 LogLevel warn

 CustomLog "path to this site's access.log"

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

And inside the ports.conf is this: (I've started with the *:80 instead of the 127.0.0.1) – same results as described above:

Listen 80
NameVirtualHost 127.0.0.1

I'm wondering about the doc sentence of: "You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries." That is all I'm trying to do, essentially a developing environment where I can work on multiple sites locally. I can't find this "hosts" file, but I'm wondering if I entered my first two domains (a long time ago) and forgot how I did it. ??

Thanks for any help.

Best Answer

The answer was in the /etc/hosts file. To discover IP addresses for names the systems DNS resolver will (should) first look to the /etc/hosts file for name=ip, if not there it goes on a DNS search. Read "man hosts" to see the syntax for the hosts file. Assign all of your domains (preferrably not FQDN) the ip # of your localhost (127.0.0.1) example:

127.0.0.1 localhost.exmaplesite1.com
127.0.0.1 localhost.exmaplesite2.com

Use the localhost.examplesite1.com and localhost.examplesite2.com as your ServerName in your VirtualHost directive. See the docs link for other settings and syntax. @Antonious use of a sole wildcard is not documented by Apache2 - but he did not understand I was trying to force certain names through a localhost loopback so that I could develop web applications offline. I never understood @lynxman's assumption that a "Bad Request" or "Server Not Found" error could write to the error logs to begin with - though I was using separate log files for each VirtualHost directive anyway.

BTW: "sudo host localhost.examplesite.com" will print out the IP address for the site IF 'examplesite.com' is an actual site. Apparently the "sudo host " command does NOT look for the /etc/hosts settings and influence on the IP. <-- yeah, I know, that screwed me over good.

cheers!