How to include subdomain specific configuration files
I have been researching for days to include subdomain specific configuration files in subdomain virtual host configuration that is in main server configuration file. My overall goal is to add proxy pass and proxy pass reverse configuration that are different in each subdomain. For example: I want sub1.domain.com to act as proxy server of tomcat server that is running in localhost port 8080 and sub2.domain.com of another tomcat running in 8081. But cpanel generated httpd.conf file doesn't allow to add subdomain specific configuration files. For example: here's my httpd.conf file.
Notice the include directory is same for all subdomain's virtual host configuration. So if I add a subdomain specific proxy configuration file in above directory, that configuration is included in all virtualhost. I also couldn't achieve proxy configuration using .htaccess. So the only option I think I have is to edit vhost.default template which seems little complicate for me. Is there any other solution of this problem beside customizing vhost template?
ServerName sub1.domain.com
ServerAlias www.sub1.domain.com
...
Include "/usr/local/apache/conf/userdata/std/2/domain/*.conf"
ServerName sub2.domain.com
ServerAlias www.sub2.domain.com
...
Include "/usr/local/apache/conf/userdata/std/2/domain/*.conf"
Notice the include directory is same for all subdomain's virtual host configuration. So if I add a subdomain specific proxy configuration file in above directory, that configuration is included in all virtualhost. I also couldn't achieve proxy configuration using .htaccess. So the only option I think I have is to edit vhost.default template which seems little complicate for me. Is there any other solution of this problem beside customizing vhost template?
-
Hello, You could try using a custom template with rules that add specific lines for certain domain names. There's an example of how this would work on the following post: Editing IfModule mod_include.c on virtualhost permanently Thank you. 0 -
I recently ran into this problem too and discovered that cpanel does support subdomain specific virtual host includes. However, the include line is not added to the httpd.conf file until after you create the subdomain specific include file and run the script to regenerate virtual hosts. The virtual host template file appears to do a directory existence check deciding to add the Include line. The steps I did: 1: Create Subdomain Specific .conf Files in: /etc/apache2/conf.d/userdata/ssl/2/username/sub.example.com/test.conf /etc/apache2/conf.d/userdata/std/2/username/sub.example.com/test.conf
2: Regenerate Virtual Hosts/scripts/ensure_vhost_includes --user=username
3: Find the new Includes in httpd.conf for just your subdomain:ServerName sub.example.com ServerAlias www.sub.example.com ... Include "/usr/local/apache/conf/userdata/std/2/username/*.conf" Include "/usr/local/apache/conf/userdata/std/2/username/sub.example.com/*.conf"0 -
I recently ran into this problem too and discovered that cpanel does support subdomain specific virtual host includes. However, the include line is not added to the httpd.conf file until after you create the subdomain specific include file and run the script to regenerate virtual hosts. The virtual host template file appears to do a directory existence check deciding to add the Include line. The steps I did: 1: Create Subdomain Specific .conf Files in:
/etc/apache2/conf.d/userdata/ssl/2/username/sub.example.com/test.conf /etc/apache2/conf.d/userdata/std/2/username/sub.example.com/test.conf
2: Regenerate Virtual Hosts/scripts/ensure_vhost_includes --user=username
3: Find the new Includes in httpd.conf for just your subdomain:ServerName sub.example.com ServerAlias www.sub.example.com ... Include "/usr/local/apache/conf/userdata/std/2/username/*.conf" Include "/usr/local/apache/conf/userdata/std/2/username/sub.example.com/*.conf"
It worked out quite well. Thanks a million Zeddic. I had so much trouble without this information and sorry for delayed response, I had very busy schedule to try it out.0
Please sign in to leave a comment.
Comments
3 comments