You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by John Nichel <jn...@kegworks.com> on 2013/05/02 18:35:50 UTC

[users@httpd] Determining whether 'NameVirtualHost' has been previously called

Hi all,

  I'm setting a new web server that will handle multiple 'satellite' web
sites for my place of employment.  These sites currently exist on an
Apache 1.3 server and the previous admin configured them all in the main
httpd.conf file.  I want to make this easier to maintain, so I am setting
up a config file for each virtual host in /etc/httpd/conf.d (ie
satsite1.conf, satsite2.conf, etc.)  I'm trying to find a way to determine
if "NameVirtualHost 1.2.3.4:80" has already been called in a previously
loaded conf file.  Looking through the docs, I wasn't able to find what I
was looking for in the virtual hosts section, and was hoping someone here
had a suggestion.  I could just define all the IP's that handle the vhosts
in the main config file, but, if for whatever reason, one of those IP
addresses doesn't currently have a vhost assigned to it, I get the warning
" NameVirtualHost 1.2.3.4:80 has no VirtualHosts".  Not an error, I know,
but my OCD doesn't like it.  :)  I thank you in advance for any advice you
may have.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Determining whether 'NameVirtualHost' has been previously called

Posted by Norman Peelman <np...@cfl.rr.com>.
On 05/02/2013 12:35 PM, John Nichel wrote:
> Hi all,
>
>    I'm setting a new web server that will handle multiple 'satellite' web
> sites for my place of employment.  These sites currently exist on an
> Apache 1.3 server and the previous admin configured them all in the main
> httpd.conf file.  I want to make this easier to maintain, so I am setting
> up a config file for each virtual host in /etc/httpd/conf.d (ie
> satsite1.conf, satsite2.conf, etc.)  I'm trying to find a way to determine
> if "NameVirtualHost 1.2.3.4:80" has already been called in a previously
> loaded conf file.  Looking through the docs, I wasn't able to find what I
> was looking for in the virtual hosts section, and was hoping someone here
> had a suggestion.  I could just define all the IP's that handle the vhosts
> in the main config file, but, if for whatever reason, one of those IP
> addresses doesn't currently have a vhost assigned to it, I get the warning
> " NameVirtualHost 1.2.3.4:80 has no VirtualHosts".  Not an error, I know,
> but my OCD doesn't like it.  :)  I thank you in advance for any advice you
> may have.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

John,

   Put the 'NameVirtualHost' directive in the main config file, you only 
need it once and you'll know it's been called (it's either/or really, 
you can't use Name based and IP based virtualhosts at the same time). 
Now for any request not matching one of your virtualhosts 
(NameVirtualHosts matched against the ServerName and ServerAlias 
directives as defined inside each virtual host) Apache will default to 
the virtualhost that was defined (meaning processed first from the 
config files), so make the first one a 'dummy', 'site map' or the main site.

   For example (from my main config apache2.conf for 2.2, yours would be 
httpd.conf) I have:

   # following file has 'Listen 80' directive
   Include /etc/apache2/ports.conf
   # for you, 'Listen 80' in httpd.conf

   # this tells apache to listen on all interfaces
   NameVirtualHost *

   # Include the virtual host configurations 
(/etc/apache2/sites-enabled/vhosts.conf):
   Include /etc/apache2/sites-enabled/

   which contains entries such as:

   # First VirtualHost is default

#default
<VirtualHost *>
    ServerAdmin <admin-email-address>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/var/www/default" --------------->(change this to 
point to where you want mis-directed requests to go)
    DirectoryIndex index.php index.htm

    ErrorLog /var/log/apache2/default-error.log
    CustomLog /var/log/apache2/default-access.log common

    ErrorDocument 400 "Quite simply, a Bad Request..."
    ErrorDocument 404 "I'm really not sure what you're looking for but, 
it's not here..."

    <Location /server-status>
       SetHandler server-status
       Order deny,allow
       Deny from all
       Allow from 127.0.0.1
       Allow from localhost
    </Location>
</VirtualHost>

#site 1
<VirtualHost *>
    ServerAdmin <admin-email-address>
    ServerName example.com ---------------->(replace this with site 1)
    ServerAlias www.example.com ----------->(replace this with site 1)
    DocumentRoot "/var/www/site1"
    DirectoryIndex index.php index.htm

    ErrorLog /var/log/apache2/site1-error.log
    CustomLog /var/log/apache2/site1-access.log common

    ErrorDocument 400 "Quite simply, a Bad Request..."
    ErrorDocument 404 "I'm really not sure what you're looking for but, 
it's not here..."

    <Location /server-status>
       SetHandler server-status
       Order deny,allow
       Deny from all
       Allow from 127.0.0.1
       Allow from localhost
    </Location>
</VirtualHost>

...site2, site3, site4 and so on.

-- 
Norman Registered Linux user #461062 -Have you been to www.apache.org yet?-


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org