我怎样才能configurationApache每个HTTP错误500发送电子邮件

我有一些服务器应用程序在apache2上运行; Ruby on Rails,PHP和其他。

在所有情况下,我希望apache发送电子邮件,每当Apache响应HTTP错误500内部服务器错误。

我怎样才能做到这一点?

您可以创build一个自定义的500文件。 假设你正在使用Apache,你可以在你的.htaccess中添加下面一行

ErrorDocument 500 /errorfilename.php 

此代码基本上告诉服务器,如果用户遇到500(内部服务器错误)错误,以显示errorfilename.php。

在这个PHP文件中,你可以添加代码,当用户进入500时发邮件给你。

 <?php //this is the 500 error php file mail([email protected],500 error encountered,'message here'); ?> <html> <head> <title>500</title> <body> 500 internal server error The administrator has been notified <a href="index.php">Go to Homepage</a> </body> </html> 

您可以使用ErrorDocument指令来传递自定义错误消息,并使该文件成为发送电子邮件的脚本。 或者,编写错误页面,以便使用任何想要的信息写入文件,并设置一个cron作业将这些文件发送给您。