httpd.conf sites/www.domain.com.conf Wildcard DNS

ttremain

Well-Known Member
Feb 16, 2003
279
6
168
cPanel Access Level
Root Administrator
I need to make a wildcard virtualhost entry in httpd.conf. However the newer configuration requires me to modify the /usr/local/apache/conf/sites/*.conf files instead. This is no problem. I just need to add ServerAlias *.domain.com

However, here's where it starts to get sticky. I have other virtualhosts that use the same SLD, forum.domain.com, etc...

Two questions:

1) How do I make sure that the virtualhost I'm modifying with the wildcard entry is used LAST in the httpd.conf?

2) How do I rebuild the httpd.conf after making the change?

Thank you!
 

JawadArshad

Well-Known Member
PartnerNOC
Apr 8, 2008
459
7
68
PK
cPanel Access Level
DataCenter Provider
I need to make a wildcard virtualhost entry in httpd.conf. However the newer configuration requires me to modify the /usr/local/apache/conf/sites/*.conf files instead. This is no problem. I just need to add ServerAlias *.domain.com

However, here's where it starts to get sticky. I have other virtualhosts that use the same SLD, forum.domain.com, etc...

Two questions:

1) How do I make sure that the virtualhost I'm modifying with the wildcard entry is used LAST in the httpd.conf?

2) How do I rebuild the httpd.conf after making the change?

Thank you!

What cPanel version are you using, usually cPanel creates the VirtualHosts by using files in /var/cpanel/userdata/username folder. You can make changes in the /var/cpanel/userdata/username/domain.tld files and create the ServerAlias for wildcard, then you can rebuild the httpd.conf file with these changes by running /usr/local/cpanel/bin/build_apache_conf and then restart the service, the wildcard will work fine. Don't forget to create the wildcard cname in DNS zone file.
 

ttremain

Well-Known Member
Feb 16, 2003
279
6
168
cPanel Access Level
Root Administrator
Are you just looking to create a wildcard subdomain (*.exmaple.com), or is there more to what you are doing than just creating a wildcard subdomain?
Yes, I am just wanting to create the wildcard subdomain, and make sure it ends up in the httpd.conf AFTER any other occurrences of subdmain.domain.com
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Yes, I am just wanting to create the wildcard subdomain, and make sure it ends up in the httpd.conf AFTER any other occurrences of subdmain.domain.com
Creating the wildcard subdomain is the easy part: just go into cPanel and when creating a subdomain, just create *.example.com (where example.com is a domain). However, cPanel/WHM does not have the mechanisms in place to control where the httpd.conf entries for this are placed. It's generally not recommended to create *.example.com and also create something.example.com in the cPanel interface.
 

ttremain

Well-Known Member
Feb 16, 2003
279
6
168
cPanel Access Level
Root Administrator
What cPanel version are you using, usually cPanel creates the VirtualHosts by using files in /var/cpanel/userdata/username folder. You can make changes in the /var/cpanel/userdata/username/domain.tld files and create the ServerAlias for wildcard, then you can rebuild the httpd.conf file with these changes by running /usr/local/cpanel/bin/build_apache_conf and then restart the service, the wildcard will work fine. Don't forget to create the wildcard cname in DNS zone file.
cPanel 11.23.6-R27698

Will rebuilding the httpd.conf like this ensure that this virtualhost is positioned in the httpd.conf after any other virtualhosts that use a subdomain from this same domain?

Unless things have changed too drasticly, the wildcard virtualhost, (*.domain.com) should be after any other virtualhosts. (subdoamin.domain.com) in the httpd.conf
 

ttremain

Well-Known Member
Feb 16, 2003
279
6
168
cPanel Access Level
Root Administrator
Creating the wildcard subdomain is the easy part: just go into cPanel and when creating a subdomain, just create *.example.com (where example.com is a domain). However, cPanel/WHM does not have the mechanisms in place to control where the httpd.conf entries for this are placed. It's generally not recommended to create *.example.com and also create something.example.com in the cPanel interface.
Then I will just make a recomendation that they move either this wildcard subdomain, or the static subdomains, to a different server. Problem solved.