Apache - Name Based Virtual Hosting - 2 IP Addresses
I should be missing something, somewhere. I have basically following settings related with this in the configuration files - I did read and apply the same thing in Apache documentation as well as many other sources.
Listen 80
<virtualhost *:80="">ServerName example1.com
# ...</virtualhost>
<virtualhost *:80="">ServerName example3.com
# ...</virtualhost>
<virtualhost 2.2.2.2:80="">ServerName example2.com
# ...</virtualhost>
I have example2.com pointed to 2.2.2.2 and and the others to 1.1.1.1 in DNS records.
I can go to example1.com and example3.com successfully but example2.com goes to default server, which is example1.com for this sample since it was entered first in the configuration.
Another weirdness: keeping DNS same for example2.com but change vhost config to be *:80 and it opens the website and server ip is reported as 1.1.1.1 as I can get from the web script to see what's going on.
And another one: Even I keep only example2.com domain in the configuration and remove others, it still doesn't work with the IP. As I tried to mention, if I enter 2.2.2.2, it successfully access to the server via this IP.
Could someone please help me to solve this problem which is obviously caused by something I am doing wrong or missing.
Thank you very much in advance.
4 Replies
Just in case someone else does the same mistake:
You really need to disable Auto Configure Network in Configuration Profile.
You should be able to run apache2ctl -S
(for Debian based distros) or apachectl -S
(for Red Hat based distros) to see which virtual host are loaded by Apache, their assigned IPs/ports, and server names. This can help make sure the right information is being loaded.
Also, for the example you gave, if you're going to explicitly use an IP address for the third vhost, I would use your first IP address for the other two vhost. Otherwise they are still configured to use ALL IPs.
@smozgur:
My bad.
Just in case someone else does the same mistake:
You really need to disable Auto Configure Network in Configuration Profile.
How does one "disable Auto Configure Network in Configuration Profile?"
@rfeliciano:
You should be able to run
apache2ctl -S
(for Debian based distros) orapachectl -S
(for Red Hat based distros) to see which virtual host are loaded by Apache, their assigned IPs/ports, and server names. This can help make sure the right information is being loaded.
I am having trouble getting apache to display my pages. I believe that the request is being received by my server, but the only page that is displayed is the Apache default page. Can someone point me to some debug techniques that will help me isolate this problem. The result of my apachectl -S request follows:
[bobheath@example ~]$ apachectl -S
VirtualHost configuration:
45.79.xxx.yy:80 is a NameVirtualHost
default server www.example1.com (/etc/httpd/conf/httpd.conf:1013)
port 80 namevhost www.example1.com (/etc/httpd/conf/httpd.conf:1013)
alias example1.com
port 80 namevhost www.example2.com (/etc/httpd/conf/httpd.conf:1022)
alias example2.com
port 80 namevhost www.example3.com (/etc/httpd/conf/httpd.conf:1031)
alias example3.com
Syntax OK
[bobheath@example ~]$