如果域不存在,是否阻止Apache显示第一个虚拟主机?

okxuctiv  于 2023-03-24  发布在  Apache
关注(0)|答案(1)|浏览(89)

不知道什么时候,但WHM/cPanel和/或Apache已经改变了他们处理不存在的域的请求的方式。
以前它会重定向到http://requested-domain.tld/cgi-sys/defaultwebpage.cgi,但现在它只会显示虚拟主机中列出的第一个域的内容,而不会更改域。
我尝试添加以下变量:

  • /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>

也不将请求重定向到http://requested-domain.tld/cgi-sys/defaultwebpage.cgi
有人有什么建议吗?

v64noz0r

v64noz0r1#

将以下内容添加到/etc/apache2/conf.d/includes/pre_virtualhost_global.conf解决了问题:

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

对于具有多个IP地址的服务器,您需要为每个IP进行复制。
https://support.cpanel.net/hc/en-us/articles/360061002473-How-do-I-set-a-default-VirtualHost-for-each-IP-address-

相关问题