0

Not sure when but WHM/cPanel and/or Apache have changed how they handle requests for domains that do not exist.

Previously it would redirect to http://requested-domain.tld/cgi-sys/defaultwebpage.cgi however it will now simply show the content of the first domain listed in the virtual hosts without changing the domain.

I've tried adding variations of the following to:

  • /etc/apache2/conf.d/includes/pre_virtualhost_2.conf
  • /etc/apache2/conf.d/000-default.conf
<VirtualHost *>
  ServerName subdomain.server-domain.tld
  RedirectPermanent / /cgi-sys/defaultwebpage.cgi
  #RewriteEngine on
  #RewriteCond %{HTTPS} on
  #RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  #RewriteCond %{HTTPS} off
  #RewriteRule ^/(.*)$ /cgi-sys/defaultwebpage.cgi [L,R=302]
</VirtualHost>

Neither redirect the request to http://requested-domain.tld/cgi-sys/defaultwebpage.cgi

Does anyone have any suggestions?

Gavin
  • 101
  • 2
  • We don't do questions that involve cpanel. – vidarlo Mar 16 '23 at 16:04
  • Hi @vidarlo, I'll re-post on SO. – Gavin Mar 16 '23 at 16:07
  • apache has always selected the first virtualhost when no match is found for requested Host. Not new behaviour, you can not change that and there is no need. Just use the appropiate redirects to handle requests. – Daniel Ferradal Mar 16 '23 at 16:10
  • @DanielFerradal Apache is ignoring my attempts to inject a VirtualHost before all the others and I'm not able to find any documentation that covers how to handle scenarios where a customer leaves, we remove their account but they don't update their DNS. This results in the domain rendering a completely unrelated website. – Gavin Mar 16 '23 at 18:33
  • Change the mindset, it is not ignoring anything, you are doing it wrong. Apache loads virtualhost in alphabetical order by name if there are many files in the same Include, so file names may be important. In any case check the results with "apachectl -S" command. – Daniel Ferradal Mar 17 '23 at 10:45

1 Answers1

0

Adding the following to /etc/apache2/conf.d/includes/pre_virtualhost_global.conf resolved the issue:

<VirtualHost xxx.xxx.xxx.xxx:80>
    ServerName xxx.xxx.xxx.xxx
    DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost xxx.xxx.xxx.xxx:443>
    ServerName xxx.xxx.xxx.xxx
    DocumentRoot /var/www/html
    <IfModule suphp_module>
        suPHP_UserGroup nobody nobody
    </IfModule>
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    <IfModule ssl_module>
        SSLEngine on

        SSLCertificateFile /var/cpanel/ssl/cpanel/cpanel.pem
        SSLCertificateKeyFile /var/cpanel/ssl/cpanel/cpanel.pem
        SSLCertificateChainFile /var/cpanel/ssl/cpanel/cpanel.pem
        SSLUseStapling Off
    </IfModule>
    <IfModule security2_module>
        SecRuleEngine On
    </IfModule>
</VirtualHost>

For servers with multiple IP addresses, you are required to replicate for each IP.

https://support.cpanel.net/hc/en-us/articles/360061002473-How-do-I-set-a-default-VirtualHost-for-each-IP-address-

Gavin
  • 101
  • 2