There may come some situations where we would need to add a secondary IP to virtual hosts.

Regardless of the motive(s) behind the need, this is how it's done according to the EA4 templating system:

The first step is to duplicate the core template files:
rsync -av /var/cpanel/templates/apache2_4/ssl_vhost.default /var/cpanel/templates/apache2_4/ssl_vhost.local
rsync -av /var/cpanel/templates/apache2_4/vhost.default /var/cpanel/templates/apache2_4/vhost.local


Once done we'll need to tweak the local templates.

We'll find the following at the very first line of code on both files:
<VirtualHost [% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %] >


For keeping it simple, we'll use IP "192.168.11.2" in this example.

Let's modify it with our secondary IP (and port) so it become:

For /var/cpanel/templates/apache2_4/vhost.local
<VirtualHost [% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %] 192.168.11.2:80 >

For /var/cpanel/templates/apache2_4/ssl_vhost.local
<VirtualHost [% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %] 192.168.11.2:443 >

 

Once done, let's rebuild Apache's configuration the web server by running the following command:
/scripts/rebuildhttpdconf

The best practices are telling us to inspect the end result.  So let's see how we did (don't forget to use your IP and not one in this example):
cat /etc/apache2/conf/httpd.conf | grep '192.168.11.2'

The output should look like this...
[root@sandbox ~]# cat /etc/apache2/conf/httpd.conf | grep '192.168.11.2'
<VirtualHost 192.168.11.2:80 15.235.42.210:80 >
<VirtualHost 192.168.11.2:80 15.235.42.210:80 >
<VirtualHost 192.168.11.2:80 15.235.42.210:80 >
<VirtualHost 192.168.11.2:80 15.235.42.210:80 >
<VirtualHost 192.168.11.2:80 15.235.42.210:80 >
...

It everything seems fine, time to reload...
/etc/init.d/httpd restart


That's it!

Was this answer helpful? 0 Users Found This Useful (0 Votes)