Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a need for one of the VirtualHosts that WHM is pulling from cPanel when automatically building httpd.conf to be placed last, because it uses a wildcard subdomain. Example:

<VirtualHost XX.XX.XX.XX:80>
    ServerName app1.example.com
    ServerAlias *.app1.example.com
</VirtualHost>

<VirtualHost XX.XX.XX.XX:80>
    ServerName app2.example.com
    ServerAlias *.app2.example.com
</VirtualHost>

<VirtualHost XX.XX.XX.XX:80>
    ServerName example.com
    ServerAlias *.example.com
</VirtualHost>

I'd like any request to foo.app1.example.com to go to the first VirtualHost, bar.app2.example.com to go to the second, etc. Any other request is handled by the main domain. bar.example.com or foo.example.com goes to the last VirtualHost.

This would all work just fine if the 3rd VirtualHost was listed last. However, because of how WHM is configured, whenever I run scripts that automatically build httpd.conf, they are re-ordered, the third VirtualHost block is placed first, and I lose the ability to contact app1.example.com or app2.example.com because *.example.com is a match first.

Any ideas on how to get WHM to respect the order I want? I looked into the perl script /usr/local/cpanel/bin/userdata_update as was recommended here:

http://docs.cpanel.net/twiki/bin/view/EasyApache3/EA3Overview

...but couldn't make heads or tails of it. Perl isn't my strongest language.

Any suggestions?

share|improve this question
add comment

1 Answer

cPanel builds a hash array of the domains in each user account and then iterates through them to build the httpd.conf. There is not any way I know of to set a custom order for this. If you are going to do this example.com can't be defined inside cPanel and then you need to add the vhost manually using the cPanel includes editor:

http://docs.cpanel.net/twiki/bin/view/AllDocumentation/WHMDocs/IncludeEditor

specificity: Post VirtualHost

Keep in mind though, if you change the IP for your domain, this will not be updated etc.

share|improve this answer
    
Yeah, thanks for this. I don't think there's a way to not define exmaple.com but use cPanel to define subdomains of "example.com". Do you know of a way? –  thexfactor Oct 25 '11 at 19:55
    
sure make the subdomain be the main domain of the account and add other subdomains as addon domains ;) –  n8whnp Oct 26 '11 at 3:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.