LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache virtualhost with 2 ip's (http://www.linuxquestions.org/questions/linux-newbie-8/apache-virtualhost-with-2-ips-761416/)

djroy 10-12-2009 01:07 PM

Apache virtualhost with 2 ip's
 
Hello,

I have Apache 2.2.14 on Suse linux 10.3.
That's is ok, and works fine.

Now come's the problem, i have 2 ip addresses, and 2 domains.
Now must Apache listen on the first ip, for the first domain.
And the second ip for the second domain.

But, if i go to the second domain in my browser i will come on the first domain out.

Example:

ip1: 192.168.100.210
Domain1: first-domain.com

ip2: 192.168.100.211
Domain2: second-domain.com

This is my httpd-vhosts
Code:

#NameVirtualHost *:80

<VirtualHost 192.168.100.210:80>
    DocumentRoot "/usr/local/apache2/htdocs"
    ServerName first-domain.com
    ServerAlias www.first-domain.com
</VirtualHost>

<VirtualHost 192.168.100.211:80>
    DocumentRoot "/home/roy/public_html/second-domain.com"
    ServerName second-domain.com
    ServerAlias www.second-domain.com
</VirtualHost>

This does not work correctly.
When i both IP addresses replace with a wilcard (*) , then it's will works fine.

Can any one my help me?
I don't see what i did wrong...

r3sistance 10-12-2009 01:35 PM

you should uncomment the following line.

#NameVirtualHost *:80

to

NameVirtualHost *:80

This is the line that allows for multiple domains to be hosted on the same port...

djroy 10-12-2009 02:48 PM

I think i have found the solution...

This is now the httpd-vhosts.conf

Code:

NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache2/htdocs"
    ServerName first-site.com
    ServerAlias www.first-site.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/home/roy/public_html/second-site.com"
    ServerName second-site.com
    ServerAlias www.second-site.com
</VirtualHost>

<VirtualHost 192.168.100.211:80>
    DocumentRoot "/home/roy/public_html/second-site.com"
    ServerName second-site.com
    ServerAlias www.second-site.com
</VirtualHost>

<Directory /home/roy/public_html/second-site.com>
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

The first-site.com shows now the first site, and second-site.com shows the second site, on the second ip.

192.168.100.210 shows now the first site, and is the default, all other sites (that not defined is in the config) goes to the first site

192.168.100.211 shows now the second site.


All times are GMT -5. The time now is 10:04 PM.