大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 sho…

问题原文

原帖链接 · Gavin · CC BY-SA 4.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 · CC BY-SA 4.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-

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-03-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。