繁体   English   中英

如何配置 apache 以在未配置的子域上返回 404?

[英]How do I configure apache to return 404 on unconfigured subdomains?

I am self-hosting a website on a Debian computer with apache, and in my DNS configuration I have set all subdomains of my domain (*.mydomain.com) to go to the IP of my Debian computer. 如何配置 apache 以便如果有人转到没有虚拟主机的子域,我为每个子域都有一个单独的文件,他们会收到 404 错误,而不是看到根域上的内容? 我尝试编辑 000-default.conf 文件并将以下内容放入其中:

<VirtualHost *:80>
        ServerName null
        Redirect 404 /
</VirtualHost>

<VirtualHost *:443>
        ServerName null
        Redirect 404 /
</VirtualHost>

但是现在当我到达 mydomain.com 时,我收到以下错误:

This site can’t provide a secure connection
mydomain.com sent an invalid response.
ERR_SSL_PROTOCOL_ERROR

奇怪的是,如果我 go 到我为 mydomain.com 配置的子域之一,它工作正常,我看到应该在子域上的页面。

对于端口 443,您必须配置 ssl。 这就是为什么它不起作用。 我相信只有当您使用 HTTPS 访问该站点时才会发生这种情况。 – Chi.C.J.Rajeeva Lochana

谢谢Chi.C.J.Rajeeva Lochana ,现在效果很好! 不过,有一个小问题,如果我 go 到www.subdomain.mydomain.com那么我得到一个Your connection is not private错误。 有什么解决办法吗?

 Your connection is not private

错误消息来自所使用的证书,该证书可能对您要连接的域无效。 *.mydomain.com 等通配符证书对“third-Level.mydomain.com”有效,但对“somthing.third-Level.mydomain.com”无效,后者需要像“*.third-Level.mydomain.com”这样的通配符'。

您可以从 Let's Encrypt ( https://letsencrypt.org/ ) 获得免费且有效的通配符证书

并且,不要将端口 443 添加到000-default.conf ,而是使用default-ssl.conf文件。 使用a2enconf default-ssl启用default-ssl.conf ,然后从000-default.conf中删除443 然后,使用systemctl restart apache2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM