order of VirtualHost sections in httpd.conf: loading dedicated ip loads addondomain.com instead of domain.com

horizon2021

Active Member
Jan 31, 2021
25
1
3
USA
cPanel Access Level
Root Administrator
Restored a few accounts to a new server with no errors reported, but found one small issue. When I visit the dedicated IP for one of the accounts, it loads one of that domain's addon domain's sites instad of the main domain site. I would like visiting the dedicated IP to show the contents of the accounts primary domain not the addon or subdomain.

Looking at /etc/apache2/conf/httpd.conf I see the order of the VirtualHost is:

Code:
<VirtualHost 1.2.3.4:80>
  ServerName addondomain.domain.com
  ServerAlias addondomain.com
... (73 lines total)
# To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/username/addondomain.com.domain.com/*.conf"
</VirtualHost>

<VirtualHost 1.2.3.4:80>
  ServerName domain.com
  ServerAlias www.domain.com
... (73 lines total)
# To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/username/domain.com/*.conf"
</VirtualHost>
If I simply edit that and move the primary domain above the addondomain.domain.com so that the domain.com section is the first to appear for the VirtualHost 1.2.3.4 then visiting 1.2.3.4 loads the domain.com content correctly.

Code:
<VirtualHost 1.2.3.4:80>
  ServerName domain.com
  ServerAlias www.domain.com
... (73 lines total)
# To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/username/domain.com/*.conf"
</VirtualHost>

<VirtualHost 1.2.3.4:80>
  ServerName addondomain.domain.com
  ServerAlias addondomain.com
... (73 lines total)
# To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/username/addondomain.com.domain.com/*.conf"
</VirtualHost>
However, will this corrected order directly in the /etc/apache2/conf/httpd.conf be overwritten?

Is there a more correct way to correct this order of the VirtualHost sections in the httpd.conf file?
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,418
1,000
313
cPanel Access Level
Root Administrator
Hey there! There's actually never been a way to specify the order that vhosts get built in cPanel, and that type of change will be overwritten the next time the Apache configuration gets written to. If you'd like the IP address to load a certain vhost, I'd recommend checking out our guide here to get a default vhost created:

 
  • Like
Reactions: horizon2021