Subdomain proxy vHost template for all users
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 ^(.*)$
-
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 /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/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 tagRewriteCond %{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/scripts/rebuildhttpdconf /scripts/restartsrv_httpd
to revert any chnages simply delete the added code and rebuild the apache again..0 -
Thanks, @techAMIGO !!!! 0
Please sign in to leave a comment.
Comments
2 comments