The Lazy Admin Blog

Home  /  Apache • cPanel  /  Allow a cPanel server to run a VHOST from multiple IP addresses

Allow a cPanel server to run a VHOST from multiple IP addresses

April 03, 2018 Apache, cPanel 4 Comments

Every once in a while a hosting provider has to change an IP address for a single user or even an entire server on the fly. If you’ll try do this the usual way, by changing the IP address in WHM you can expect downtime ranging from several minutes to several hours until the DNS cache is cleared.

While cPanel does not officially allow accounts to have more than one IP address, there is no such restriction for Apache. So the solution is to override the default cPanel configurations with your own.

In the first example I will show you how to do this with a single site and in the second one I will focus on the entire server.

  1. Change a single site to work from multiple IP addresses:

In this example we want to alter the domain example.com which runs on the IP
address: 185.20.1.1 to also run on the IP address: 185.20.2.2 – assuming that both IP addresses are already configured on the server.

Apache’s configuration file is automatically generated at on of the following locations.

On EASY APACHE 4 based servers:

# /etc/apache2/conf/httpd.conf

On EASY APACHE 3 based servers:

# /usr/local/apache/conf/httpd.conf

And a large capital letters warning us:

DO NOT EDIT. AUTOMATICALLY GENERATED. USE INCLUDE FILES IF YOU NEED TO MAKE A CHANGE

While there is no use editing the file, we can pull all the VHOST info from it.

It will look like this:

<VirtualHost 185.20.1.1:80 >
 ServerName example.com
 ServerAlias mail.example.com www.example.com
 DocumentRoot /home/example/public_html
 ServerAdmin webmaster@example.com
 UseCanonicalName Off

... more settings here ...

</VirtualHost>

If you are using an SSL certificate there is another block for the SSL virutal host:

<VirtualHost 185.20.1.1:443 >
 ServerName example.com
 ServerAlias mail.example.com www.example.com
 DocumentRoot /home/example/public_html
 ServerAdmin webmaster@example.com
 UseCanonicalName Off

... more settings here ...

</VirtualHost>

We need to copy both of these blocks to the file:

/usr/local/apache/conf/includes/pre_virtualhost_global.conf

for EasyApache3

OR

/etc/apache2/conf.d/includes/pre_virtualhost_global.conf

for EasyApache4

Afterwards edit the opening line on each VHOST block so it includes both of the first and the second IP addresses like:

<VirtualHost 185.20.1.1:80 185.20.2.2:80>

...vhost settings...

</VirtualHost>

<VirtualHost 185.20.1.1:443 185.20.2.2:443>

...vhost settings...

</VirtualHost>

Save and run:

/scripts/rebuildhttpdconf

make sure you get no errors and then restart Apache:

/scripts/restartsrv_httpd

That’s it, you’re good to go 😉

 

2. Change a server to load from multiple IP addresses:

Instead of copying an entire VHOST, as in the previous example, we will edit the default template that cPanel uses to build VirtualHosts.

Step 1:
 cd /var/cpanel/templates/apache2_4/

Step 2:

cp vhost.default vhost.local
cp ssl_vhost.default ssl_vhost.local

Step 3: Edit each file:

In the vhost.local file change the first line from:

<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %]>

To:

<VirtualHost 185.20.1.1:80 185.20.2.2:80 >

In ssl_vhost.local file change the first line from:

<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %]>

To:

<VirtualHost 185.20.1.1:443 185.20.2.2:443 >

Step 4:

/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

By completing all the above steps, all of the accounts on the server will run from both IPs addresses.

If you have accounts that uses a private IP address, you can use a combination of both methods. Change the template to run from the two main addresses as in method 2 and then copy the the virtual host settings as in method 1, but remember to change the IP address to the site’s private IP address.

Tags: apache, cPanel
Previous Article
Next Article

Related Posts

  • Convert JetBackup to cPanel structure

    Convert JetBackup to cPanel structure

    October 6, 2022
  • Enable TLS 1.1/1.0 on cPanel servers

    Enable TLS 1.1/1.0 on cPanel servers

    September 30, 2022
  • cPanel :: Safely restore an account after enabling NGiNX

    cPanel :: Safely restore an account after enabling NGiNX

    May 23, 2019

4 Comments

  1. Khan Reply
    October 28, 2019 at 08:28

    Thanks for sharing this.

    Since I have many IP’s to use, I tried adding to vhost.default and to ssl_vhost.default.

    After rebuilding the httpd.conf and restarting apache, my website would redirect to /cgi-sys/defaultwebpage.cgi

    Would you know how to get things working with *:80 and *:443?

    Cheers!

    • Oleg Drabkin Reply
      October 28, 2019 at 09:04

      Hi Khan, please note you are not supposed to edit the vhost.default and ssl_vhost.default files themselves, rather you are supposed to copy them to:
      vhost.local
      ssl_vhost.local
      and then edit those files.

      • Khan Reply
        October 28, 2019 at 10:05

        Hello Oleg,

        Yes, I actually copied vhost.default and ssl_vhost.default to vhost.default.bk and ssl_vhost.default.bk.

        Whenever I added a specific server IP to and , the website would work fine.

        However, when I change the serverp:80 and serverip:443 to *:80 and *:443, the website would redirect to /cgi-sys/defaultwebpage.cgi

        I would like the VirtualHost to be like and so websites could run on all IP’s. Would you know how this can be done? ?

        Thank you

      • Khan Reply
        October 28, 2019 at 11:08

        It seems my last comment was modified by your firewalls. I have shared my comment in the screenshot here https://prnt.sc/pp3tfj

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh VMFS WHM Wordpress xenserver

Popular Posts

  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • How To Install & Configure a Galera Cluster with MySQL on Centos 7 February 6, 2018
  • Libmodsecurity installation April 14, 2016
  • JetBackup Cheat Sheet :: Automatically Acknowledge Alerts November 15, 2018

Recent Posts

  • rsync without prompting for password October 10, 2022
  • Convert JetBackup to cPanel structure October 6, 2022
  • Configure LiteSpeed Crawler October 5, 2022
  • Change Hostname in Oracle Cloud Infrastructure (OCI) October 3, 2022

Recent Comments

  • Anonymous on InnoDB: Failed to find tablespace for table `X` in the cache
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Oleg Drabkin on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
Privacy Policy • Contact