The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to include subdomain specific configuration files

Discussion in 'EasyApache' started by Mani Rai, Feb 22, 2017.

  1. Mani Rai

    Mani Rai Registered

    Joined:
    Feb 22, 2017
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Kathmandu, Nepal
    cPanel Access Level:
    Root Administrator
    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.

    Code:
    <VirtualHost *:80>
      ServerName sub1.domain.com
      ServerAlias www.sub1.domain.com
      ...
     Include "/usr/local/apache/conf/userdata/std/2/domain/*.conf"
    </VirtualHost>
    <VirtualHost *:80>
      ServerName sub2.domain.com
      ServerAlias www.sub2.domain.com
      ...
     Include "/usr/local/apache/conf/userdata/std/2/domain/*.conf"
    </VirtualHost>
    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?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Mani Rai likes this.
  3. Zeddic

    Zeddic Registered

    Joined:
    Feb 26, 2017
    Messages:
    1
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    NA
    cPanel Access Level:
    Root Administrator
    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:

    Code:
    /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
    Code:
    /scripts/ensure_vhost_includes --user=username
    
    3: Find the new Includes in httpd.conf for just your subdomain:
    Code:
    <VirtualHost *:443>
      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"
    </VirtualHost>
    
     
    Mani Rai likes this.
  4. Mani Rai

    Mani Rai Registered

    Joined:
    Feb 22, 2017
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Kathmandu, Nepal
    cPanel Access Level:
    Root Administrator
    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.
     
    cPanelMichael likes this.
Loading...

Share This Page