You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Kai Hendry <he...@cs.helsinki.fi> on 2004/07/15 15:52:14 UTC

[users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Can I configure apache to automagically look in
/web/subdomain.mydomain.org for a vhost on the ip of my server?

For example. On a client machine I can:
sudo echo 62.220.235.20 made.it.up >> /etc/hosts

And when putting in made.it.up in my browser, I would get a 404. :)
Unless I mkdir /etc/make.it.up on my server.



Right now my configuration is real pain in the ass[1].

In my monstrous httpd.conf, I have somewhere my vhosts listed like so:

NameVirtualHost 62.220.235.20:80                                                                                                                                              
                                                                                                                                                                              
<VirtualHost www.dabase.com dabase.com>                                                                                                                                       
    Include conf/dabase.com.conf                                                                                                                                              
</VirtualHost>                                                                                                                                                                

...

What is the point of NameVirtualHost? I still have to put in the IP, as
thanks to:
http://httpd.apache.org/docs/dns-caveats.html

I have since learnt to put in the ip address and use ServerName to
avoid errors like:
error.log:[Thu Jul 15 00:32:37 2004] [error] Cannot resolve host name test.natalian.org --- ignoring!

<VirtualHost 62.220.235.20>                                                                                                                                                   
    Include conf/test.natalian.org.conf                                                                                                                                       
</VirtualHost> 

All my sites are pretty much the same. I override any settings with .htaccess.
So my configurations in /etc/apache/conf duplicate each other:

bilbo$ diff -u test.natalian.org.conf tips.natalian.org.conf 
--- test.natalian.org.conf      2004-07-15 16:00:17.000000000 +0300
+++ tips.natalian.org.conf      2004-07-15 00:38:55.000000000 +0300
@@ -1,10 +1,10 @@
-  CustomLog /var/log/apache/test.natalian.org-access_log combined
-  ServerAdmin test@natalian.org
-  ServerName test.natalian.org
+  CustomLog /var/log/apache/tips.natalian.org-access_log combined
+  ServerAdmin tips@natalian.org
+  ServerName tips.natalian.org
 
-DocumentRoot /web/test.natalian.org
+DocumentRoot /web/tips.natalian.org
 
-  <Directory "/web/test.natalian.org">
+  <Directory "/web/tips.natalian.org">
     Options All
     AllowOverride All
     Order allow,deny


So ideally I would not have to edit httpd.conf, make a new configuration
file and restart apache everytime I start a new web project.  I also
forgot to update httpd.conf when my machine switched to another IP. That
was another painful exp I would like to avoid.

[1] http://db.cs.helsinki.fi/~hendry/faqwiz/faqw.py?req=show&file=faq01.083.htp

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Posted by Kai Hendry <he...@cs.helsinki.fi>.
On Fri, Jul 16, 2004 at 12:21:39 +0300, Kai Hendry wrote:
> But how I do DocumentRoot, ScriptAlias and Alias in

I need to do DocumentRoot somehow with .htaccess when using vhost
alias..

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Posted by Kai Hendry <he...@cs.helsinki.fi>.
In my httpd.conf I tried both:

UseCanonicalName    Off                                                                                                                                                       
VirtualDocumentRoot /web/%0                                                                                                                                                   
LogFormat "%V %h %l %u %t \"%r\" %>s %b" vhost_common                                                                                                                         
CustomLog /var/log/apache/access_log vhost_common                                                                                                                             
Options All                                                                                                                                                                   
                                                                                                                                                                              
NameVirtualHost 62.220.235.20:80                                                                                                                                              
<VirtualHost svn.natalian.org>                                                                                                                                                
    Include conf/svn.natalian.org.conf                                                                                                                                        
</VirtualHost>


But that doesn't work either:
[Fri Jul 16 00:36:47 2004] [error] [client 217.30.176.161] File does not
exist: /web/svn.natalian.org/

Can they not work together some how? These two types of vhost
directives?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3 or 2

Posted by Kai Hendry <he...@cs.helsinki.fi>.
On Thu, Jul 15, 2004 at 07:53:20 -0400, Joshua Slive wrote:
> Doing DocumentRoot in .htaccess would defeat the whole purpose of
> mod_vhost_alias, which is to set the DocumentRoot based on the
> hostname.  It sounds like you should exclude this vhost from
> mod_vhost_alias.  You can do this as follows:

In the case of my svn repository I agree, but for example I have a site
where directory index is needed and now shows up in the URL all the
time:
http://trip.natalian.org/moin.cgi/FrontPage
It used to be just:
http://trip.natalian.org/FrontPage

I guess I need to fix this with a rewrite rule.

And it would be nice to do Alias from .htaccess. Umm, rewrite rule
again? /me shivers...




Your vhost suggestions did the trick btw!
http://svn.natalian.org/debian/configuration/bilbo/httpd.conf

Thank you very much, =)

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Posted by Joshua Slive <js...@gmail.com>.
On Fri, 16 Jul 2004 00:21:39 +0300, Kai Hendry <he...@cs.helsinki.fi> wrote:
> On Thu, Jul 15, 2004 at 10:02:50 -0400, Joshua Slive wrote:
> > On Thu, 15 Jul 2004 16:52:14 +0300, Kai Hendry <he...@cs.helsinki.fi> wrote:
> > > Can I configure apache to automagically look in
> > > /web/subdomain.mydomain.org for a vhost on the ip of my server?
> >
> > I think you are looking for mod_vhost_alias. See:
> > http://httpd.apache.org/docs-2.0/mod/mod_vhost_alias.html
> 
> Excellent. I've got it going, but some of my sites are a little tricky
> to convert to a vhost. For example:
> 
> bilbo$ cat /etc/apache/conf/svn.natalian.org.conf
>     CustomLog /var/log/apache/svn.natalian.org-access_log combined
> 
>     ServerAdmin spam@natalian.org
>     ServerName svn.natalian.org
> 
>     DocumentRoot /usr/lib/cgi-bin/viewcvs.cgi
>     RewriteEngine On
>     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
>     <Directory /usr/lib/cgi-bin>
>             SetHandler cgi-script
>             Options ExecCGI
>     </Directory>
> 
>     Alias /viewcvs/ /usr/share/viewcvs/
> 
>     LogLevel warn
> 
>     ServerSignature On
> 
> Ok I can lost the customlog as I understand apache can't have many files
> open when I am running lots of vhosts.
> 
> But how I do DocumentRoot, ScriptAlias and Alias in
> /web/svn.natalian.org 's .htaccess?

Doing DocumentRoot in .htaccess would defeat the whole purpose of
mod_vhost_alias, which is to set the DocumentRoot based on the
hostname.  It sounds like you should exclude this vhost from
mod_vhost_alias.  You can do this as follows:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName anything.goes.here
VirtualDocumentRoot ...
etc...
</VirtualHost>

<VirtualHost *:80>
ServerName svn.natalian.org
DocumentRoot ...
etc ...
</VirtualHost>

Any host that does not match a specific ServerName will get served by
the VirtualDocumentRoot in the first <VirtualHost> section.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Posted by Kai Hendry <he...@cs.helsinki.fi>.
On Thu, Jul 15, 2004 at 10:02:50 -0400, Joshua Slive wrote:
> On Thu, 15 Jul 2004 16:52:14 +0300, Kai Hendry <he...@cs.helsinki.fi> wrote:
> > Can I configure apache to automagically look in
> > /web/subdomain.mydomain.org for a vhost on the ip of my server?
> 
> I think you are looking for mod_vhost_alias. See:
> http://httpd.apache.org/docs-2.0/mod/mod_vhost_alias.html

Excellent. I've got it going, but some of my sites are a little tricky
to convert to a vhost. For example:

bilbo$ cat /etc/apache/conf/svn.natalian.org.conf
    CustomLog /var/log/apache/svn.natalian.org-access_log combined

    ServerAdmin spam@natalian.org
    ServerName svn.natalian.org

    DocumentRoot /usr/lib/cgi-bin/viewcvs.cgi
    RewriteEngine On
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory /usr/lib/cgi-bin>
            SetHandler cgi-script
            Options ExecCGI
    </Directory>

    Alias /viewcvs/ /usr/share/viewcvs/

    LogLevel warn

    ServerSignature On


Ok I can lost the customlog as I understand apache can't have many files
open when I am running lots of vhosts.

But how I do DocumentRoot, ScriptAlias and Alias in
/web/svn.natalian.org 's .htaccess? 

They seem not allowed! :/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimizing Virtual host(s) configuration on apache 1.3.31

Posted by Joshua Slive <js...@gmail.com>.
On Thu, 15 Jul 2004 16:52:14 +0300, Kai Hendry <he...@cs.helsinki.fi> wrote:
> Can I configure apache to automagically look in
> /web/subdomain.mydomain.org for a vhost on the ip of my server?

I think you are looking for mod_vhost_alias. See:
http://httpd.apache.org/docs-2.0/mod/mod_vhost_alias.html

> What is the point of NameVirtualHost? I still have to put in the IP, as
> thanks to:
> http://httpd.apache.org/docs/dns-caveats.html

In the normal case, you can make this even simpler by using *:80 as
the argument to the NameVirtualHost and VirtualHost directives.  See:
http://httpd.apache.org/docs-2.0/vhosts/name-based.html#using

The point of NameVirtualHost is to allow you to deal with more complex
cases where some IP addresses are doing IP-virtual hosting and some
are doing name-virtual hosting.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org