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/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
# ErrorLog logs/dummy-host.example.co m-error_lo g
# CustomLog logs/dummy-host.example.co m-access_l og common
</VirtualHost>
<VirtualHost *:80>
# ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/nexu s
ServerName www.pic.bejhan.com
# ErrorLog logs/dummy-host.example.co m-error_lo g
# CustomLog logs/dummy-host.example.co m-access_l og 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?
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
# ErrorLog logs/dummy-host.example.co
# CustomLog logs/dummy-host.example.co
</VirtualHost>
<VirtualHost *:80>
# ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.pic.bejhan.com
# ErrorLog logs/dummy-host.example.co
# CustomLog logs/dummy-host.example.co
</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?
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/h tdocs/nexu s
ServerName www.pic.bejhan.com
ServerAlias pic.bejhan.com
# ErrorLog logs/dummy-host.example.co m-error_lo g
# CustomLog logs/dummy-host.example.co m-access_l og common
</VirtualHost>
ServerAlias is a way of saying 'this is another name for this server'.
# 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/h
ServerName www.pic.bejhan.com
ServerAlias pic.bejhan.com
# ErrorLog logs/dummy-host.example.co
# CustomLog logs/dummy-host.example.co
</VirtualHost>
ServerAlias is a way of saying 'this is another name for this server'.
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.
ASKER
Actually there is another problem:
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
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/h tdocs 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/h tdocs/miss ing it is just sent to C:/Server/Apache/Apache2/h tdocs.
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
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/h
Perhaps it is an obvious question, but did you restart the server after making the configuration change?
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/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
</VirtualHost>
example:
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
</VirtualHost>
What if you declare pic.behjan.com explicitly, like:
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
ServerName pic.bejhan.com
</VirtualHost>
and restart the server - does it then see pic.bejhan.com ?
You have the Listen 80
and
NameVirtualHost *
correct?
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName pic.bejhan.com
</VirtualHost>
and restart the server - does it then see pic.bejhan.com ?
You have the Listen 80
and
NameVirtualHost *
correct?
ASKER
I have my virtual hosts set up like this now:
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
ServerName *.bejhan.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
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?
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName *.bejhan.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/Server/Apache/Apache2/h
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/h tdocs
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName pic.bejhan.com
ServerAlias *.bejhan.com
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
</VirtualHost>
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/h
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName pic.bejhan.com
ServerAlias *.bejhan.com
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
</VirtualHost>
ASKER
I don't think it has a problem with the IP address...
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
ServerName pic.bejhan.com
</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/miss ing
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.
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/Server/Apache/Apache2/h
ServerName pic.bejhan.com
</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
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???
Listen 80
in your configuration file???
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...
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?
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)
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\h tdocs
</VirtualHost>
# Catch all
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName *.bejhan.com
ServerAdmin webmaster@bejhan.com
DocumentRoot C:\Server\Apache\Apache2\h tdocs\miss ing
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName www.bejhan.com
ServerAlias bejhan.com
ServerAdmin webmaster@bejhan.com
DocumentRoot C:\Server\Apache\Apache2\h
</VirtualHost>
# Catch all
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName *.bejhan.com
ServerAdmin webmaster@bejhan.com
DocumentRoot C:\Server\Apache\Apache2\h
</VirtualHost>
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/h tdocs
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs
ServerName bejhancom.sytes.net
</VirtualHost>
#<VirtualHost *:80>
# DocumentRoot C:/Server/Apache/Apache2/h tdocs/nexu s
# ServerName pic.bejhan.com
#</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h tdocs/nexu s
ServerName *.bejhan.com
</VirtualHost>
I receive the error:
[warn] _default_ Virtualhost overlap on port 80, the first has precedence
Having this setup:
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName www.bejhan.com
ServerAlias bejhan.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
ServerName bejhancom.sytes.net
</VirtualHost>
#<VirtualHost *:80>
# DocumentRoot C:/Server/Apache/Apache2/h
# ServerName pic.bejhan.com
#</VirtualHost>
# Catch all
<VirtualHost _default_:*>
ServerAdmin webmaster@bejhan.com
DocumentRoot C:/Server/Apache/Apache2/h
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?
However, 'pic.bejhan.com' does seem to go to the same place as www.bejhan.com still - what should I see there?
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).
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?
(1) VirtualHosts are working
(2) They can't overlap and work properly.
Does this answer your questions now?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ahh i c well thats good enuff forme
hope all works out smoothly for you!
NameVirtualHost *
?