Score:0

Prevent Apache from showing first virtual host if domain does not exist?

om flag

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?

vidarlo avatar
ar flag
We don't do questions that involve cpanel.
Gavin avatar
om flag
Hi @vidarlo, I'll re-post on SO.
ezra-s avatar
ru flag
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.
Gavin avatar
om flag
@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.
ezra-s avatar
ru flag
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.
Score:0
om flag

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-

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.