Link to home
Start Free TrialLog in
Avatar of bejhan
bejhan

asked on

Virtual Hosts

I have been trying to set up virtual hosts on my Apache 2.x.x. From my registar godaddy.com I have set my domain as parked but have used total dns control to direct www to my IP address as well as pic to my IP address. Here are my virtual hosts:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

<VirtualHost *:80>
#   ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/nexus
    ServerName www.pic.bejhan.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

For some reason pic.bejhan.com does not work (i tried servername of www.pic and also pic) if I comment out the first server then www and pic direct to the documentroot of pic.bejhan.com how can I correct this?
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

do you have following directive in the main part of your httpd.conf:
NameVirtualHost *
?
ramazanyich is correct;  you need two statements in your httpd.conf as well as the virtual host:

# Tell apache to listen to all requests on port 80
Listen 80

# Tell Apache that we are doing name-based virtual hosting for all IP addresses on port 80
NameVirtualHost *

Additionally, if you want pic.bejhan.com to work as well as www.pic.bejhan.com, you have to not only set up DNS for both pic.bejhan.com and www.pic.bejhan.com, but you have to modify your second virtual host statement as follows:

<VirtualHost *:80>
#   ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/nexus
    ServerName www.pic.bejhan.com
    ServerAlias pic.bejhan.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

ServerAlias is a way of saying 'this is another name for this server'.

Avatar of bejhan
bejhan

ASKER

Yes  I had those statements, I just didn't include and I knew about the serveralias part too I think I found my problem sorry for the trouble.
Avatar of bejhan

ASKER

Actually there is another problem:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

# Catch all
<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName *.bejhan.com
</VirtualHost>

When I use http://bejhan.com and http://www.bejhan.com it works fine and goes to C:/Server/Apache/Apache2/htdocs but when I use http://pic.bejhan.com (which is registered to my IP address as well) I am not directed to C:/Server/Apache/Apache2/htdocs/missing it is just sent to C:/Server/Apache/Apache2/htdocs.
Perhaps it is an obvious question, but did you restart the server after making the configuration change?
Avatar of bejhan

ASKER

Yes I did restart the server and did it one more time just to make sure :) But sometimes the answer is actually that simple... but unfortunately not this time.
Create a default settings for non www.bejhan.com requests

example:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

<VirtualHost _default_:*>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
</VirtualHost>

What if you declare pic.behjan.com explicitly, like:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

# Catch all
<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName pic.bejhan.com
</VirtualHost>

and restart the server - does it then see pic.bejhan.com ?  

You have the Listen 80
and
NameVirtualHost *

correct?

Avatar of bejhan

ASKER

I have my virtual hosts set up like this now:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

# Catch all
<VirtualHost _default_:*>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName *.bejhan.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName pic.bejhan.com
</VirtualHost>

pic.bejhan.com is sent to the www.bejhan.com documentroot. It seems as though pic.bejhan.com and www.bejhan.com are just being directed to the IP address and the virtual hosts are not affecting anything?
try to set the ip address at NameVirtualHost instead *
I agree with mrielf - even though it shouldn't matter, you should try using the actual IP address in the NameVirtualHost setting, and even in the VirtualHost, like the following (where your ip address is xxx.xxx.xxx.xxx).  

I've also moved the ServerName first, as that makes it a bit easier to read.  Order is also important - pic.bejhan.com wouldn't have been found in the config that you gave above as the catchall would have been found first.

Finally, I combined the last two entries.

Listen 80
NameVirtualHost xxx.xxx.xxx.xxx

<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName www.bejhan.com
    ServerAlias bejhan.com
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
</VirtualHost>

<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName pic.bejhan.com
    ServerAlias *.bejhan.com
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
</VirtualHost>

Avatar of bejhan

ASKER

I don't think it has a problem with the IP address...

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName pic.bejhan.com
</VirtualHost>

# Catch all
<VirtualHost _default_:*>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/missing
    ServerName *.bejhan.com
</VirtualHost>

I had that but it told me that there was an overlap on port 80... so that may have something to do with it.
Do you have the configuration statement:

Listen 80

in your configuration file???
Avatar of bejhan

ASKER

yes i do
Instead

     NameVirtualHost xxx.xxx.xxx.xxx

     <VirtualHost xxx.xxx.xxx.xxx:80>

try:

     NameVirtualHost xxx.xxx.xxx.xxx

     <VirtualHost xxx.xxx.xxx.xxx>

or

     NameVirtualHost xxx.xxx.xxx.xxx:80

     <VirtualHost xxx.xxx.xxx.xxx:80>


Maybe...

I agree, particulary with the idea of trying:

NameVirtualHost xxx.xxx.xxx.xxx:80

<VirtualHost xxx.xxx.xxx.xxx:80>
...
</VirtualHost>

When you run the following command:

apachectl configtest

Do you get any errors?

... OH!  I just noticed that you are running under Windows.  What Operating System?

(I mean, what version of Windows)
Avatar of bejhan

ASKER

windows xp professional
It occurs to me that we are using Linux style paths, not Windows (which uses forward slashes instead of backslashes).  Have you tried:

<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName www.bejhan.com
    ServerAlias bejhan.com
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:\Server\Apache\Apache2\htdocs
</VirtualHost>

# Catch all
<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName *.bejhan.com
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:\Server\Apache\Apache2\htdocs\missing
</VirtualHost>

Avatar of bejhan

ASKER

Yes I used the backslash instead but that gave me double slashes.

Having this setup:

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName www.bejhan.com
    ServerAlias bejhan.com
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs
    ServerName bejhancom.sytes.net
</VirtualHost>

#<VirtualHost *:80>
#   DocumentRoot C:/Server/Apache/Apache2/htdocs/nexus
#    ServerName pic.bejhan.com
#</VirtualHost>

# Catch all
<VirtualHost _default_:*>
    ServerAdmin webmaster@bejhan.com
    DocumentRoot C:/Server/Apache/Apache2/htdocs/nexus
    ServerName *.bejhan.com
</VirtualHost>

I receive the error:

[warn] _default_ Virtualhost overlap on port 80, the first has precedence
That's correct - there *is* an overlap there.  www.bejhan.com and *.bejhan.com both match for www.bejhan.com.  However, for www.bejhan.com, the first entry will 'win' as it is first - isn't that what you want?

However, 'pic.bejhan.com' does seem to go to the same place as www.bejhan.com still - what should I see there?
Avatar of bejhan

ASKER

well i want pic.bejhan.com to go to a different page as it is not defined so it shoudl go to the catchall shouldn't it?
What happens (just for testing) when you comment out the default, and uncomment the pics.bejhan.com section?
(I'm wondering if it doesn't like the overlap).
Avatar of bejhan

ASKER

in that case pic goes to its defined place...
the correct spot?  Then we know:

(1) VirtualHosts are working
(2) They can't overlap and work properly.

Does this answer your questions now?
Avatar of bejhan

ASKER

No because... the catchall account doesn't function correctly as when the virtual hosts are analyzed it sees that pic.bejhan.com is not defined it sends it to the www.bejhan.com location instead of *.bejhan.com
ASKER CERTIFIED SOLUTION
Avatar of periwinkle
periwinkle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bejhan

ASKER

ahh i c well thats good enuff forme
hope all works out smoothly for you!