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?
LVL 1
bejhanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ramazanyichCommented:
do you have following directive in the main part of your httpd.conf:
NameVirtualHost *
?
0
periwinkleCommented:
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'.

0
bejhanAuthor Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bejhanAuthor Commented:
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.
0
periwinkleCommented:
Perhaps it is an obvious question, but did you restart the server after making the configuration change?
0
bejhanAuthor Commented:
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.
0
mrielfCommented:
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>

0
periwinkleCommented:
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?

0
bejhanAuthor Commented:
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?
0
mrielfCommented:
try to set the ip address at NameVirtualHost instead *
0
periwinkleCommented:
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>

0
bejhanAuthor Commented:
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.
0
periwinkleCommented:
Do you have the configuration statement:

Listen 80

in your configuration file???
0
bejhanAuthor Commented:
yes i do
0
mrielfCommented:
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...

0
periwinkleCommented:
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?

0
periwinkleCommented:
(I mean, what version of Windows)
0
bejhanAuthor Commented:
windows xp professional
0
periwinkleCommented:
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>

0
bejhanAuthor Commented:
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
0
periwinkleCommented:
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?
0
bejhanAuthor Commented:
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?
0
periwinkleCommented:
What happens (just for testing) when you comment out the default, and uncomment the pics.bejhan.com section?
0
periwinkleCommented:
(I'm wondering if it doesn't like the overlap).
0
bejhanAuthor Commented:
in that case pic goes to its defined place...
0
periwinkleCommented:
the correct spot?  Then we know:

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

Does this answer your questions now?
0
bejhanAuthor Commented:
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
0
periwinkleCommented:
It looks like if you define www.bejhan.com, you can't use a catchall because of the overlap, though.  

Your original question had to do with just getting the virtualhosts working, and we've now proved that they do work, as if you remove the 'default' (with the overlap), the two separate entries work.

Maybe you could do this instead:

<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 a*.bejhan.com
    ServerAlias b*.bejhan.com
    ServerAlias c*.bejhan.com
</VirtualHost>

(etc. for each letter of the alpha other than w?)  Basically, it appears you can't have two ServerName's the match www.bejhan.com or else it will dismiss the default.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bejhanAuthor Commented:
ahh i c well thats good enuff forme
0
periwinkleCommented:
hope all works out smoothly for you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.