Apache2的。 为所有虚拟主机定制相同的错误页面

我想为每个虚拟主机全局设置一次相同的自定义错误页面。

我试过放置

ErrorDocument 404 /error/404.html 

 /etc/apache2/conf.d/localized-error-pages 

要么

 /etcf/apache2/apache2.conf 

但是这些设置只有在我使用我的VPS的IPtypes(例如32.56.210.12/blahblah)键入一个不存在的页面时才起作用,而如果我尝试使用虚拟主机上不存在的页面,则这些设置不起作用。 在这种情况下,规范错误显示“请求的URL / blahblah没有在这台服务器上find”。

根据文档 , ErrorDocument指令可以具有可以是文本,外部url或本地url的操作,例如:

 ErrorDocument 500 /cgi-bin/crash-recover ErrorDocument 500 "Sorry, our script crashed. Oh dear" ErrorDocument 404 http://example.com/error404.html ErrorDocument 404 /Lame_excuses/not_found.html 

这意味着它必须是VirtualHost自己的DocumentRoot的redirect或url。 您可以通过将其设置为全局别名来实现此目的,例如:

 Alias /error/404.html /var/www/error/404.html