4

Is it possible to configure an Apache (v2.x, running under Plesk 10.4.4) virtual host to listen to two IP addresses at once? We are moving a site from one IP on the server to a different IP (so that we can install an SSL - SNI isn't an option, unfortunately) and would like the site to remain active on both IPs to avoid downtime until the DNS changes complete.

So at the moment it's on, say, 1.1.1.1 - we'd like it to continue working on 1.1.1.1 but ALSO work on 1.1.1.2 at the same time until DNS finishes, then it can just be 1.1.1.2.

Is this as simple as copying the Virtual Host entry and changing the IP or is there more / less to it than that?

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
MikkyX
  • 95
  • 3
  • 12
  • [Administration panels are off topic](http://serverfault.com/help/on-topic). [Even the presence of an administration panel on a system,](http://meta.serverfault.com/q/6538/118258) because they [take over the systems in strange and non-standard ways, making it difficult or even impossible for actual system administrators to manage the servers normally](http://meta.serverfault.com/a/3924/118258), and tend to indicate low-quality questions from *users* with insufficient knowledge for this site. – HopelessN00b Feb 26 '15 at 07:51

3 Answers3

6

If your apache configuration uses the common conventions it already listens at all interfaces, by simply configuring the second IP-address at OS level your website will be reachable on both IP's

E.g. the relevant lines you would often see:

...
Listen 80  
NameVirtualHost *:80
...
<VirtualHost *:80>
  ServerName dummy-host.example
  DocumentRoot /www/docs/dummy-host.example
</VirtualHost>

Now if you have bound Apache to specific IP-addresses your config would look more like something below and you will need to change your configuration:

...
Listen 10.9.8.7:80  
NameVirtualHost 10.9.8.7:80
...
<VirtualHost 10.9.8.7:80>
  ServerName dummy-host.example
  DocumentRoot /www/docs/dummy-host.example
</VirtualHost>

N.B. When changing ip-addresses don't overlook entries in /etc/hosts

HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • So if I just change the IP address currently in to a * that will do it? Hope Plesk will allow me to do that without trying to get in the way. – MikkyX Feb 05 '14 at 14:54
  • Plesk's NameVirtualHost entry was commented out so I put that in place for ports 80 and 443. I then changed the default vhost config template to *:80 and *:443 in the tag, and rebuilt the config for the domain in question. Once Apache was restarted the domain started showing the Plesk default page. Suspect something else within Plesk is interfering so I'll have to keep digging. – MikkyX Feb 06 '14 at 13:44
  • Plesk is interfering too much, I can't find a way past it. I know your answer is correct though, so I'm going to accept it. – MikkyX Feb 06 '14 at 14:19
  • :) That's often the case with general purpose tooling, they try to protect you from advanced functionality. Good luck with your migration. – HBruijn Feb 06 '14 at 15:28
1

Yes, it can be done. Exactly how you need to change your config depends on how it's setup currently. Copying your virtualhost to have a second one with the new IP address is almost certainly the wrong way.

Read the apache vhost documentation. Change your config, try it out. If it doesn't work, post back with a specific question showing the config you're using, what you tried, what you expect to happen, and what happened instead. Include relevant logfile extracts.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
  • I'll have a look and feedback as soon as I can. The config files are, as I've hinted in my original post, generated by Plesk but I believe I can override these with my own where needed. – MikkyX Feb 05 '14 at 14:52
  • Most people here wouldn't recommend using any of those "admin GUIs" professionally. I have to admit that I have no idea of how the config it creates will look - if I had your apache config files available I could tell you immediately how to do it, but I haven't the faintst idea of what Plesk or any other of those things would do it. – Jenny D Feb 05 '14 at 14:57
  • If I had my way I'd probably ditch Plesk, but alas, here we are. I'll see what I can do, anyway. Thanks! – MikkyX Feb 05 '14 at 15:00
  • Good luck, if you don't get it to work please update the question with config examples or post a new question. At least I can assure you that it **is** possible, if that helps! – Jenny D Feb 05 '14 at 15:03
0

If you are using DNS records, let's say www.myhost.com pointing to 1.1.1.1 but then pointing to 1.1.1.2. You simply have to change your dns server records to point to the new ip address. Your virtual host entry is probably similar to:

<VirtualHost www.myhost.com:80>
ServerAdmin webmaster@myhost.com
DocumentRoot //www
ServerName www.myhost.com
ErrorLog /logs/error_log
TransferLog /logs/access_log
</VirtualHost>

As we can see, this host entry doesn't show any ip address hard link. Therefore, the apache server will simply respond to any request sent for www.myhost.com.

Note that apache will need to listen on both ip address until you decommit the old one.

Let us know how it worked.

Alex Rouge
  • 104
  • 4
  • If the virtualhost entry looks like that, it's already not working. THe domain name does not go where you put it. – Jenny D Feb 05 '14 at 14:31
  • 1
    It works but apache will resolve the address when it will load the configuration. Which means, the virtualhost will be active only on the first address resolved by Apache. Which is not the wanted solution of course – stoned Feb 05 '14 at 14:53
  • Thanks @stoned, I'd forgotten that that option was added some time ago. I will now instead complain that the `DocumentRoot` is wrong - and, as you say, that it also doesn't solve the actual problem. – Jenny D Feb 05 '14 at 14:59
  • Of course I put a "similar" without high level of details. However the idea remains. Sorry for being not very exhaustive and for poor english. as well as for //. ;) – Alex Rouge Feb 05 '14 at 15:17