Operating System & Version
CloudLinux v7.9.0
cPanel & WHM Version
106.0.9

Gamecock

Member
Dec 22, 2019
5
0
1
/mnt/backup
cPanel Access Level
Root Administrator
I want the subdomain foo.exmple.com point to 127.0.0.1:8080 (via ProxyPass or ProxyPassReverse) for all of the users of cPanel server.

I want to apply this modification on default virtual host template effect all users accounts. (Looks like cpanel.example.com which is pointing to example.com:2082)

I can do this via .htaccess file:

RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:8080/$1 [P,L]

But it only works per account while there are +1000 domains on my server and I can't repeat that manually. (Also the user can delete or modify .htaccess file)
How can I perform that for all accounts/domains?

I know I should perform changes in Include Editor section of Apache Configuration, But I don't know which part of that and what statement to write.

I use Litespeed 6.0.1 on cPanel (CloudLinux)
 

techAMIGO

Well-Known Member
Nov 6, 2019
59
41
18
Kerala, india
cPanel Access Level
Root Administrator
HI Gamecock

generally,if common unique rules needs to be affected to all virtual host you can add the rules to any of the following files

Code:
/etc/apache2/conf.d/userdata/custom_rule.conf
/etc/apache2/conf.d/includes/pre_virtualhost_global.conf
/etc/apache2/conf.d/includes/post_virtualhost_global.conf
but according to your requirement, each domain should have separate proxy pass where example.com will vary so above method will not work .
so in order to achieve that ,

you can edit the following apache template files

Code:
/var/cpanel/templates/apache2_4/vhost.default
/var/cpanel/templates/apache2_4/ssl_vhost.default
and add the following code at the end but just before the virtual host closing tag </virtualhost>

Code:
   RewriteCond %{HTTP_HOST} !^foo.[% vhost.servername %]$
   RewriteCond %{HTTP_HOST} ^foo\.
   RewriteCond %{HTTP:Upgrade} !websocket   [nocase]  
   ProxyPass "/" "http://127.0.0.1:8080" 
   ProxyPassReverse "/"  http://127.0.0.1:8080/
this is just a sample and you can change the code accordingly based on the requirement

after that rebuild the apache conf and restart apache , then all virtual host will be added with above apache settings automatically

Code:
/scripts/rebuildhttpdconf 
/scripts/restartsrv_httpd
to revert any chnages simply delete the added code and rebuild the apache again..
 
  • Like
Reactions: cPRex