Virtualmin Changes binding from ip:80 to *:80 and breaks older configs … FIX


We have found some virtualmin installs will change the format of new virtualhosts from ip:80 to *:80 sometimes which breaks virtualhosts as the *:80 overrides the ip:80.
This can result in websites showing another website content, and usually shows up right after you add a new domain in virtualmin.


When you run apachectl -S it will show things like this

*:80                   is a NameVirtualHost
         default server domain1.co.nz (/etc/apache2/sites-enabled/domain1.co.nz.conf:1)
         port 80 namevhost domain1.co.nz (/etc/apache2/sites-enabled/domain1.co.nz.conf:1)
                 alias www.domain1.co.nz
                 alias webmail.domain1.co.nz
                 alias admin.domain1.co.nz
         port 80 namevhost domain2.co.nz (/etc/apache2/sites-enabled/domain2.co.nz.conf:1)
                 alias www.domain2.co.nz
                 alias webmail.domain2.co.nz
                 alias admin.domain2.co.nz
192.168.1.2:80                   is a NameVirtualHost
         port 80 namevhost domain3.co (/etc/apache2/sites-enabled/domain3.co.conf:1)
                 alias www.domain3.co
                 alias webmail.domain3.co
                 alias admin.domain3.co
         port 80 namevhost domain4.nz (/etc/apache2/sites-enabled/domain4.nz.conf:1)
                 alias www.domain4.nz
                 alias webmail.domain4.nz
                 alias admin.domain4.nz

Some showing its under an IP, and others under *:80

The solution is a simple one, set them to all use *:80 by default, and update current virtualhosts to use that format also, heres how to do that

In virtualmin, login
Click System Settings -> Virtualmin Configuration -> Defaults for new domains. Look for ‘Address format for Apache virtual hosts’ and set that to ‘Always use *’

The easy way to do this by editing the config is to edit /etc/webmin/virtual-server/config and change the line apache_star to be

apache_star=2

This sets it up for new virtualhosts to use *:80

To change existing hosts to all use *:80 you can run sed to change the config
eg

sed -i s/ipaddress\:80/\*\:80/g /etc/apache2/sites-enabled/*

Use the following to check the config works

apachectl -S

This should show all domains like this

*:80                   is a NameVirtualHost
         default server domain1.co.nz (/etc/apache2/sites-enabled/domain1.co.nz.conf:1)
         port 80 namevhost domain1.co.nz (/etc/apache2/sites-enabled/domain1.co.nz.conf:1)
                 alias www.domain1.co.nz
                 alias webmail.domain1.co.nz
                 alias admin.domain1.co.nz
         port 80 namevhost domain2.co.nz (/etc/apache2/sites-enabled/domain2.co.nz.conf:1)
                 alias www.domain2.co.nz
                 alias webmail.domain2.co.nz
                 alias admin.domain2.co.nz
         port 80 namevhost domain3.co (/etc/apache2/sites-enabled/domain3.co.conf:1)
                 alias www.domain3.co
                 alias webmail.domain3.co
                 alias admin.domain3.co
         port 80 namevhost domain4.nz (/etc/apache2/sites-enabled/domain4.nz.conf:1)
                 alias www.domain4.nz
                 alias webmail.domain4.nz
                 alias admin.domain4.nz

All under *:80

As a side note: Port 443 or SSL sites usually have the IP in them, so ignore those and leave them as they are.