Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to make my server respond for 2 domains with 2 different IP each virtual host. That's the first time I do something like this, could you guys help me?

My domain1.org routes successfully to IP address 1.1.1.1, but my domain2.org does it too, when it should route to 2.2.2.2

My ports.conf looks something like this:

Listen 80
Listen 443
NameVirtualHost *:80
NameVirtualHost *:443
NameVirtualHost 2.2.2.2:80
NameVirtualHost 2.2.2.2:443

My domain1.org virtual hosts:

 <IfModule mod_ssl.c>
      <VirtualHost *:443>
           ServerName domain1.org
           # more configs...
      </VirtualHost>
 </IfModule>

 <VirtualHost *:80>
      ServerName domain1.org
 </VirtualHost>

My domain2.org virtual hosts:

 <IfModule mod_ssl.c>
      <VirtualHost 2.2.2.2:443>
           ServerName domain2.org
           # more configs...
      </VirtualHost>
 </IfModule>

 <VirtualHost 2.2.2.2:80>
      ServerName domain2.org
 </VirtualHost>

The apache doesn't show any warnings or errors, what could be wrong? Thanks in advance

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Ports.conf should look like this:

Listen 80
Listen 443
NameVirtualHost 1.1.1.1:80
NameVirtualHost 1.1.1.1:443
NameVirtualHost 2.2.2.2:80
NameVirtualHost 2.2.2.2:443
NameVirtualHost domain1.org:80
NameVirtualHost domain1.org:443
NameVirtualHost domain2.org:80
NameVirtualHost domain2.org:443

And your vHosts config:

<IfModule mod_ssl.c>
  <VirtualHost 1.1.1.1:443>
       ServerName domain1.org
       # more configs...
  </VirtualHost>
</IfModule>

<VirtualHost 1.1.1.1:80>
  ServerName domain1.org
</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost 2.2.2.2:443>
       ServerName domain2.org
       # more configs...
  </VirtualHost>
</IfModule>

<VirtualHost 2.2.2.2:80>
  ServerName domain2.org
</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost domain1.org:443>
       ServerName domain1.org
       # more configs...
  </VirtualHost>
</IfModule>

<VirtualHost domain1.org:80>
  ServerName domain1.org
</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost domain2.org:443>
       ServerName domain2.org
       # more configs...
  </VirtualHost>
</IfModule>

<VirtualHost domain2.org:80>
  ServerName domain2.org
</VirtualHost>

Actually, it COULD just be enough to move your <VirtualHost *> config to the bottom of the file. I believe apache evaluates the config nodes from top to bottom and the first that matches wins.

share|improve this answer
    
Why i have to duplicate the virtual host? In one you used the IP, and later the domain name. –  Lucas Pelegrino Mar 3 '13 at 17:00
    
It didn't work =/ –  Lucas Pelegrino Mar 3 '13 at 17:15
    
Apache usually distinguishes between 1.1.1.1 and domain1.org. Thats why you have to duplicate the vHosts (or someone will prove me wrong). Is domain2.org actually pointing at 2.2.2.2? –  Duke Mar 3 '13 at 17:35
    
No, but that's what I'm trying to do, domain2.org point to 2.2.2.2 –  Lucas Pelegrino Mar 3 '13 at 17:51
    
Well thats a whole different problem there. You have to change the DNS entry of domain2.org to point to IP 2.2.2.2. If you don't host your domains on your own DNS server this probably has to be done by the provider of your domains. Usually one can do this in the customer panel. –  Duke Mar 3 '13 at 18:09
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.