You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Sam Carleton <sc...@gmail.com> on 2007/02/21 03:44:36 UTC

[users@httpd] setting up virtual hosting

I am pulling my hair out trying to get the virtual hosting working on
my internal web server.  I need to get a test site online and I would
like to have it setup as a name based virtual host.  I am running
Apache v2.2.3 with default layout of SUSE, which consists of the main
conf file including a bunch of other files.

The virtual host is working just fine, it is the default that isn't
work!  I have added ServerName which was not there originially to
this:

ServerName internal.miltonstreet.com

And then I have this for the virtual host:

<VirtualHost _default_:80>

    ServerName      webdev.miltonstreet.com
    DocumentRoot    "/http/www/webdev.miltonstreet.com"

    ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
    CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined

    <Directory "/http/www/webdev.miltonstreet.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

I do *NOT* have a NameVirtualHost directive.

I do have this setup, where the default is *NOT* working either:

<VirtualHost *:443>
    DocumentRoot "/srv/www/htdocs"
</VirtualHost>

<VirtualHost secure.miltonstreet.com:443>

    ServerName secure.miltonstreet.com

<\VirtualHost>

What am I missing?

Sam

---------------------------------------------------------------------
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] setting up virtual hosting

Posted by Norman Peelman <np...@cfl.rr.com>.
----- Original Message ----- 
From: "matt farey" <ma...@gmail.com>
To: <us...@httpd.apache.org>
Sent: Tuesday, February 20, 2007 10:51 PM
Subject: Re: [users@httpd] setting up virtual hosting


> 
> 
> Sam Carleton wrote:
> > Matt,
> >
> > I do want to set things up as you suggested, but it isn't working.
> > When I type in the IP address, I get the webdev.miltonstreet.com site
> > on port 80 and the subversion site on port 443.  Here is what I have:
> >
> > Listen 80
> > Listen 443
> >
> > NameVirtualHost 192.168.0.4:80
> >
> > ServerAdmin scarleton@miltonstreet.com
> > ServerName internal.miltonstreet.com
> >
> > DocumentRoot "/http/www/internal"
> >
> > <VirtualHost _default_:80>
> >    ServerName internal.miltonstreet.com
> >    DocumentRoot "/http/www/internal"
> > </VirtualHost>
> >
> > <Directory "/http/www/internal">
> >    Options None
> >    AllowOverride None
> >    Order allow,deny
> >    Allow from all
> > </Directory>
> >
> > <VirtualHost webdev.miltonstreet.com:80>
> >
> >    ServerName      webdev.miltonstreet.com
> >    DocumentRoot    "/http/www/webdev.miltonstreet.com"
> >
> >    ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
> >    CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined
> >
> >    <Directory "/http/www/webdev.miltonstreet.com">
> >        Options Indexes FollowSymLinks
> >        AllowOverride None
> >        Order allow,deny
> >        Allow from all
> >    </Directory>
> >
> > </VirtualHost>
> >
> > <VirtualHost *:443>
> >    DocumentRoot "/http/www/internal"
> > </VirtualHost>
> >
> > <VirtualHost subversion.miltonstreet.com:443>
> >
> >    ServerName subversion.miltonstreet.com
> >    DocumentRoot "/http/subversion/wwwRoot"
> >
> >    <Directory /http/subversion/wwwRoot>
> >        Order Allow,Deny
> >        Allow from all
> >    </Directory>
> >
> >    # more stuff here
> >
> > </VirtualHost>
> >

  It's probably because if you have one virtual host then you have to have ALL virtual hosts.  Any traffic coming directly to your IP address will by default go to the first VH. Any traffic coming to a host name will go to the appropriate VH. My setup looks like:


NameVirtualHost *
<VirtualHost *>
    ServerAdmin xxxx@xxx.xxx
    ServerName www.your_default_site.com
    DocumentRoot "d:/xxx/xxx/default"
etc.
</VirtualHost>
<VirtualHost *>
    ServerAdmin xxxx@xxx.xxx
    ServerName www.your_other_site_#1.com
    DocumentRoot "d:/xxx/xxx/other_site_1"
etc.
</VirtualHost>
<VirtualHost *>
    ServerAdmin xxxx@xxx.xxx
    ServerName www.your_other_site_#2.com
    DocumentRoot "d:/xxx/xxx/other_site_2"
etc.
</VirtualHost>


---
Norm


---------------------------------------------------------------------
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] setting up virtual hosting

Posted by matt farey <ma...@gmail.com>.

Sam Carleton wrote:
> Matt,
>
> I do want to set things up as you suggested, but it isn't working.
> When I type in the IP address, I get the webdev.miltonstreet.com site
> on port 80 and the subversion site on port 443.  Here is what I have:
>
> Listen 80
> Listen 443
>
> NameVirtualHost 192.168.0.4:80
>
> ServerAdmin scarleton@miltonstreet.com
> ServerName internal.miltonstreet.com
>
> DocumentRoot "/http/www/internal"
>
> <VirtualHost _default_:80>
>    ServerName internal.miltonstreet.com
>    DocumentRoot "/http/www/internal"
> </VirtualHost>
>
> <Directory "/http/www/internal">
>    Options None
>    AllowOverride None
>    Order allow,deny
>    Allow from all
> </Directory>
>
> <VirtualHost webdev.miltonstreet.com:80>
>
>    ServerName      webdev.miltonstreet.com
>    DocumentRoot    "/http/www/webdev.miltonstreet.com"
>
>    ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
>    CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined
>
>    <Directory "/http/www/webdev.miltonstreet.com">
>        Options Indexes FollowSymLinks
>        AllowOverride None
>        Order allow,deny
>        Allow from all
>    </Directory>
>
> </VirtualHost>
>
> <VirtualHost *:443>
>    DocumentRoot "/http/www/internal"
> </VirtualHost>
>
> <VirtualHost subversion.miltonstreet.com:443>
>
>    ServerName subversion.miltonstreet.com
>    DocumentRoot "/http/subversion/wwwRoot"
>
>    <Directory /http/subversion/wwwRoot>
>        Order Allow,Deny
>        Allow from all
>    </Directory>
>
>    # more stuff here
>
> </VirtualHost>
>
> ---------------------------------------------------------------------
> 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
>
>
I suggest you dont bother with default for now, just comment that out,
and make the first vhost your private IP, then the second IP your public IP,
I know it sounds weird but it will cover both bases. It will work, now
the default will never be needed, if no hosts - then one of the IP
addresses.
Let me know if for some reason it doesnt, Mass irtual Hosting is a bit
different and I may have led you up the garden poath before, after
checking it appears I dont use default anywhere, but just hard code the IPs.


Listen 80
Listen 443

NameVirtualHost 192.168.0.4:80

ServerAdmin scarleton@miltonstreet.com
ServerName internal.miltonstreet.com
DocumentRoot "/http/www/internal"

#in the next two you can choose whether to have servername equal to IP
or set it to the IP
<VirtualHost 192.168.0.4:80>
#   ServerName 192.168.0.4
   ServerName internal.miltonstreet.com
   DocumentRoot "/http/www/internal"
</VirtualHost>
<VirtualHost your.public.ip.here:80>
#   ServerName your.public.ip.here
   ServerName internal.miltonstreet.com
   DocumentRoot "/http/www/internal"
</VirtualHost>

#this just has some placeholder right?
<Directory "/http/www/internal">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>


#now the only way that a request will come to here is if it matches.
<VirtualHost webdev.miltonstreet.com:80>
   ServerName      webdev.miltonstreet.com
   DocumentRoot    "/http/www/webdev.miltonstreet.com"
   ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
   CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined
   <Directory "/http/www/webdev.miltonstreet.com">
       Options Indexes FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all
   </Directory>
</VirtualHost>


<VirtualHost 192.168.0.4:443>
#   ServerName 192.168.0.4
   DocumentRoot "/http/www/internal"
</VirtualHost>
<VirtualHost your.public.ip.here:443>
#   ServerName your.public.ip.here
   DocumentRoot "/http/www/internal"
</VirtualHost>


<VirtualHost subversion.miltonstreet.com:443>
   ServerName subversion.miltonstreet.com
   DocumentRoot "/http/subversion/wwwRoot"
   <Directory /http/subversion/wwwRoot>
       Order Allow,Deny
       Allow from all
   </Directory>
   # more stuff here
</VirtualHost>

now just have
192.168.0.4 subversion.miltonstreet.com webdev.miltonstreet.com


-- 
Matthew Farey



---------------------------------------------------------------------
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] setting up virtual hosting

Posted by Sam Carleton <sc...@gmail.com>.
Matt,

I do want to set things up as you suggested, but it isn't working.
When I type in the IP address, I get the webdev.miltonstreet.com site
on port 80 and the subversion site on port 443.  Here is what I have:

Listen 80
Listen 443

NameVirtualHost 192.168.0.4:80

ServerAdmin scarleton@miltonstreet.com
ServerName internal.miltonstreet.com

DocumentRoot "/http/www/internal"

<VirtualHost _default_:80>
    ServerName internal.miltonstreet.com
    DocumentRoot "/http/www/internal"
</VirtualHost>

<Directory "/http/www/internal">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost webdev.miltonstreet.com:80>

    ServerName      webdev.miltonstreet.com
    DocumentRoot    "/http/www/webdev.miltonstreet.com"

    ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
    CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined

    <Directory "/http/www/webdev.miltonstreet.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:443>
    DocumentRoot "/http/www/internal"
</VirtualHost>

<VirtualHost subversion.miltonstreet.com:443>

    ServerName subversion.miltonstreet.com
    DocumentRoot "/http/subversion/wwwRoot"

    <Directory /http/subversion/wwwRoot>
        Order Allow,Deny
        Allow from all
    </Directory>

    # more stuff here

</VirtualHost>

---------------------------------------------------------------------
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] setting up virtual hosting

Posted by matt farey <ma...@gmail.com>.



Sam Carleton wrote:
> I am pulling my hair out trying to get the virtual hosting working on
> my internal web server.  I need to get a test site online and I would
> like to have it setup as a name based virtual host.  I am running
> Apache v2.2.3 with default layout of SUSE, which consists of the main
> conf file including a bunch of other files.
>
> The virtual host is working just fine, it is the default that isn't
> work!  I have added ServerName which was not there originially to
> this:
>
> ServerName internal.miltonstreet.com
>
> And then I have this for the virtual host:
>
> <VirtualHost _default_:80>
>
>    ServerName      webdev.miltonstreet.com
>    DocumentRoot    "/http/www/webdev.miltonstreet.com"
>
>    ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
>    CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined
>
>    <Directory "/http/www/webdev.miltonstreet.com">
>        Options Indexes FollowSymLinks
>        AllowOverride None
>        Order allow,deny
>        Allow from all
>    </Directory>
>
> </VirtualHost>
>
> I do *NOT* have a NameVirtualHost directive.
>
> I do have this setup, where the default is *NOT* working either:
>
> <VirtualHost *:443>
>    DocumentRoot "/srv/www/htdocs"
> </VirtualHost>
>
> <VirtualHost secure.miltonstreet.com:443>
>
>    ServerName secure.miltonstreet.com
>
> <\VirtualHost>
>
> What am I missing?
>
> Sam
>
> ---------------------------------------------------------------------
> 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
>
>


is that what you really want, whenever someone requests your server by
its IP you want to serve them that site?

I usually set up all domains I want by name, and then stick in default
to catch those that use the IP, and just shove them somewhere
unimportant. If they dont use the host header, they are probably not the
type I want anyway. The default goes in the main httpd.conf in case I
need to comment out the vhosts for some reason.

so heres my $0.02 (someone will tell me Im dead wrong I bet but I use
Mass Virtual Hosting for hunderds of sites)

Also not sure why you say you dont have the NameVirtualHost directive,
that needs to be there.

NameVirtualHost 10.10.10.10:80
#---------goes inside httpd.conf
<VirtualHost _default_:80>
ServerName _default_
#etc stuff that you don't care about
</VirtualHost>

#-goes inside httpd-vhosts.conf
<VirtualHost webdev.miltonstreet.com:80>
   ServerName      webdev.miltonstreet.com
   DocumentRoot    "/http/www/webdev.miltonstreet.com"
   ErrorLog /var/log/apache2/webdev.miltonstreet.com-error_log
   CustomLog /var/log/apache2/webdev.miltonstreet.com-access_log combined
   <Directory "/http/www/webdev.miltonstreet.com">
       Options Indexes FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all
   </Directory>
</VirtualHost>
<VirtualHost webdev2.miltonstreet.com:80>
   ServerName      webdev2.miltonstreet.com
   DocumentRoot    "/http/www/webdev2.miltonstreet.com"
   ErrorLog /var/log/apache2/webdev2.miltonstreet.com-error_log
   CustomLog /var/log/apache2/webdev2.miltonstreet.com-access_log combined
   <Directory "/http/www/webdev2.miltonstreet.com">
       Options Indexes FollowSymLinks
       AllowOverride None
       Order allow,deny
       Allow from all
   </Directory>
</VirtualHost>
#........


Now you should know that without the _default_ virtualhost the first of
these two vhosts will be served up, that is
webdev.miltonstreet.com if nothing else matches, so _default_ can be
thought of as a catch all that can go anywhere in any conf file and be
the one served up when nothing matches, but if you comment it out, which
ever vhosts is defined first will be served in nothing matches,


Are you on a lan, make sure that your hosts file are setup to point
webdev.miltonstreet.com to the correct IP
10.10.10.10 webdev.miltonstreet.com
in the example above.


That way everyone outside will be port forwarded from your public to the
internal IP, however if you request a server from inside you will go
straight to the private IP, rather than being directed by the public DNS
to the public IP which will cause you trouble.



Apologies if you really did want to serve a site when the IP is
requested, but usually this is not want people want as it messes up all
your cookies and so on.



-- 
Matthew Farey