SOLVED Editing IfModule mod_include.c on virtualhost permanently

SpaceCowboy

Well-Known Member
Jan 18, 2014
54
5
8
cPanel Access Level
Website Owner
I'm trying to add: Include /etc/apache2/custom.d/globalblacklist.conf
Inside httpd.conf

Code:
<IfModule mod_include.c>
    <Directory "/home/cowboy/public_html">
      SSILegacyExprParser On
     Include /etc/apache2/custom.d/globalblacklist.conf
    </Directory>
  </IfModule>
This is impossible to do.
After rebuilding the file. The include gets deleted.
If i put the the file here: /etc/apache2/conf.d/userdata/ssl/2_4/cowboy/cowboy.org/globalblacklist.conf

it won't even rebuild because the include happens in the wrong place (right before closing virtualhost).

So please, how to achieve the change showed on the code section and make it permanently after rebuild?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463

SpaceCowboy

Well-Known Member
Jan 18, 2014
54
5
8
cPanel Access Level
Website Owner
Hi i understand that but those directories add the code right before closing </VirtualHost> and i need to add my code inside <IfModule mod_include.c></IfModule>

See include below:
Code:
<IfModule mod_include.c>
   <Directory "/home/cowboy/public_html">
     SSILegacyExprParser On
    Include /etc/apache2/custom.d/globalblacklist.conf <---LINE I NEED TO ADD HERE
   </Directory>
  </IfModule>

...
..
.
..

<--- IT'S ADDING IT HERE INSTEAD
</VirtualHost>
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello,

An include file's contents will override any value that exists in the primary configuration file, so you should be able to enter a full IfModule section in $includename.conf:

Code:
  <IfModule include_module>
    <Directory "/home/cpexample01/public_html">
      SSILegacyExprParser On
     Include /etc/apache2/custom.d/globalblacklist.conf
    </Directory>
  </IfModule>
Thank you.
 

SpaceCowboy

Well-Known Member
Jan 18, 2014
54
5
8
cPanel Access Level
Website Owner
Just tried it doesn't work.

Created a file named include-globalblacklist.conf that contains:

Code:
<IfModule mod_include.c>
   <Directory "/home/cowboy/public_html">
    SSILegacyExprParser On
   Include /etc/apache2/custom.d/globalblacklist.conf
   </Directory>
  </IfModule>
/etc/apache2/conf.d/userdata/ssl/2_4/*username*/*domain*/include-globalblacklist.conf

Did /scripts/rebuildhttpdconf
Built /etc/apache2/conf/httpd.conf OK

Then check new httpd.conf find the line:
Code:
<IfModule mod_include.c>
   <Directory "/home/cowboy/public_html">
    SSILegacyExprParser On
    </Directory>
  </IfModule>
Missing the include.
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello,

You aren't going to see the actual Include line in the httpd.conf file. It's utilized based on the existence of the following line:

Code:
Include "/etc/apache2/conf.d/userdata/ssl/2_4/$username/$domain/*.conf
Could you let us know the contents of the /etc/apache2/custom.d/globalblacklist.conf file, and the specific method you are using to test it on the website after making the change?

Thank you.
 

SpaceCowboy

Well-Known Member
Jan 18, 2014
54
5
8
cPanel Access Level
Website Owner
Hello,

You aren't going to see the actual Include line in the httpd.conf file. It's utilized based on the existence of the following line:

Code:
Include "/etc/apache2/conf.d/userdata/ssl/2_4/$username/$domain/*.conf
Could you let us know the contents of the /etc/apache2/custom.d/globalblacklist.conf file, and the specific method you are using to test it on the website after making the change?

Thank you.
Hi this is the file:
github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/blob/master/conf.d/globalblacklist.conf

I cannot put it on
Code:
Include "/etc/apache2/conf.d/userdata/ssl/2_4/$username/$domain/*.conf
Because it will break apache. That include adds the file before closing virtual host and i need it to be included here:

Code:
<IfModule mod_include.c>
   <Directory "/home/cowboy/public_html">
    SSILegacyExprParser On
   Include /etc/apache2/custom.d/globalblacklist.conf <---LINE I NEED TO ADD HERE
   </Directory>
  </IfModule>
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hi this is the file:
github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/blob/master/conf.d/globalblacklist.conf
Hello,

You can modify the default Virtual Host template using the following steps:

1. Copy the Apache 2.4 default vhost template for to allow for customization:

Code:
cp -a /var/cpanel/templates/apache2_4/vhost.default /var/cpanel/templates/apache2_4/vhost.local
2. Edit /var/cpanel/templates/apache2_4/vhost.local using the editor of your preference (e.g. vi, nano) to change the entries to match your preferences. For example, you can change this entry:

Code:
  <IfModule include_module>
    <Directory "[% vhost.documentroot %]">
      SSILegacyExprParser On
    </Directory>
  </IfModule>
With:

Code:
  <IfModule include_module>
    <Directory "[% vhost.documentroot %]">
      SSILegacyExprParser On
[% IF vhost.servername == 'yourdomain.tld' -%]
 Include /etc/apache2/custom.d/globalblacklist.conf
[% ELSE -%]
#      Include /etc/apache2/custom.d/globalblacklist.conf
[% END -%]
    </Directory>
  </IfModule>
Ensure to replace "yourdomain.tld" with the domain name you want the change to apply to.

3. Save the changes to the file, and then run:

Code:
/scripts/rebuildhttpdconf
Note: You will need to complete the same steps for /var/cpanel/templates/apache2_4/ssl_vhost.default if you want to make the changes for the default SSL Virtual Host template.

Let us know if this helps.

Thank you.