Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Virtual Hosts

Posted on 2004-11-01
30
Medium Priority
?
34,502 Views
Last Modified: 2013-11-18
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?
0
Comment
Question by:bejhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 12
  • 3
  • +1
30 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 12472183
do you have following directive in the main part of your httpd.conf:
NameVirtualHost *
?
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12472293
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
 
LVL 1

Author Comment

by:bejhan
ID: 12478611
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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 1

Author Comment

by:bejhan
ID: 12478730
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12479825
Perhaps it is an obvious question, but did you restart the server after making the configuration change?
0
 
LVL 1

Author Comment

by:bejhan
ID: 12479981
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
 
LVL 5

Expert Comment

by:mrielf
ID: 12481378
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12482446
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
 
LVL 1

Author Comment

by:bejhan
ID: 12484610
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
 
LVL 5

Expert Comment

by:mrielf
ID: 12490663
try to set the ip address at NameVirtualHost instead *
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12492558
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
 
LVL 1

Author Comment

by:bejhan
ID: 12501319
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12665603
Do you have the configuration statement:

Listen 80

in your configuration file???
0
 
LVL 1

Author Comment

by:bejhan
ID: 12692296
yes i do
0
 
LVL 5

Expert Comment

by:mrielf
ID: 12699997
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12711373
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12778467
(I mean, what version of Windows)
0
 
LVL 1

Author Comment

by:bejhan
ID: 12780150
windows xp professional
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12782481
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
 
LVL 1

Author Comment

by:bejhan
ID: 12806199
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12809735
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
 
LVL 1

Author Comment

by:bejhan
ID: 12815601
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
 
LVL 15

Expert Comment

by:periwinkle
ID: 12815621
What happens (just for testing) when you comment out the default, and uncomment the pics.bejhan.com section?
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12815623
(I'm wondering if it doesn't like the overlap).
0
 
LVL 1

Author Comment

by:bejhan
ID: 12825283
in that case pic goes to its defined place...
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12830524
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
 
LVL 1

Author Comment

by:bejhan
ID: 12846070
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
 
LVL 15

Accepted Solution

by:
periwinkle earned 750 total points
ID: 12846173
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
 
LVL 1

Author Comment

by:bejhan
ID: 12847539
ahh i c well thats good enuff forme
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 12847546
hope all works out smoothly for you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question