Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Apache display error message

Status
Not open for further replies.

KevinAr18

Programmer
Apr 25, 2002
309
US
Currently Apache displays the default Internal Server Error and tells you to look at the log files.

Can it be made to display the current error (as well as a little bit of other text) instead?
 
You could use the ErrorDocument directive and make it point to a page that uses some server-side technology. For example, this should work if you have PERL installed on your server.
In .htaccess (or httpd.conf):
ErrorDocument 500 /script.pl
In script.pl:
#!/path/to/perl

my $error = 'tail -1 /path/to/error_log';
print "Content-type: text/html\n\n";
print <<_PAGE_;
<html>
<head>
<title>Error 500 - Internal Server error</title>
</head>
<body>
This is the error:<br>
$error
</body>
</html>
_PAGE_; //Daniel
 
Thanks for the script.

May I ask, where does the script go?

Also, I'm not sure what the path is to my error log.
 
Says there's an error in your script:

[Wed Jul 31 17:32:40 2002] [error] [client 127.0.0.1] Premature end of script headers: c:/sierra/op2map/cgi-bin/error.cgi
[Wed Jul 31 17:32:40 2002] [error] [client 127.0.0.1] Can't find string terminator &quot;_PAGE_&quot; anywhere before EOF at c:\sierra\op2map\cgi-bin\error.cgi line 5.
 
I have some typos in the script.. And since you're on a windows box, the tail won't work. Here is a modified version:
#!/path/to/perl

open(LOG, &quot;</path/to/error_log&quot;);
my @errors;
while (<LOG>)
{
push(@errors, $_);
}
print &quot;Content-type: text/html\n\n&quot;;
print <<_PAGE_;
<html>
<head>
<title>Error 500 - Internal Server error</title>
</head>
<body>
This is the error:<br>
$errors[$#errors]
</body>
</html>
_PAGE_

It has been a while since I worked with PERL, so I am a bit uncertain about some parts of it. //Daniel
 
This it odd. Now it gives a &quot;The page cannot be displayed&quot; message. You know the default one that is used by your browser.

It only occurs when a script encounters errors. The error log reports the following error when doing the above mentioned thing:

31 21:01:18 2002] [error] [client 127.0.0.1] Premature end of script headers: c:/sierra/op2map/cgi-bin/mapeditor/upload.cgi
[Wed Jul 31 21:01:18 2002] [error] [client 127.0.0.1] Could not open file C:\Old System\Sierra\New Folder\Outpost 2 CD.zip\mp6_01.map: No such file or directory


As a bit of information the script is trying to open that file but it's not there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top