问题
My website runs on Apache 2 with mod_perl and uses the Mason template system. I am not using any authentication system or any sessions in my website, but sometimes (at random) I get this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@admin.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
In the error log, the corresponding record is:
[Mon Dec 19 09:34:26 2011] [error] [client 127.0.0.1] Expected token not present
Server version string:
Apache/2.2.8 (Ubuntu) mod_apreq2-20051231/2.6.0 mod_perl/2.0.3 Perl/v5.8.8 Server
My browsers sends this weird cookie:
Name: BC_BANDWIDTH
Content: 1324486772745,6811
Domain: example.org
Path: /
Send For: Any kind of connection
Accessible to Script: Yes
Created: Wednesday, December 21, 2011 12:59:09 PM
Expires: When I close my browser
When I delete it, I can reload my page and it works. However after a couple of clicks the problem reappears.
Why am I getting the error in my error log? How to fix it?
回答1:
This is because of an invalid cookie set by some utilities on your app.
I faced the same problem and could not find "who" was setting the invalid cookie. So I had to edit Apache2/Cookie.pm. This is going to be the fix :
In the above pm, in the method/subroutine fetch
you can see :
my $jar = $req->jar or return;
Just comment that line and insert this new line :
my $jar = eval {$req->jar()};
回答2:
Because you omit the return statement in your solution, you had to circle the proceeding statement in an eval block as well. Otherwise you can expect a first time constellation where a function "cookie_class" is called on an undefined value what would throw an exception. Therefore
Replace additionally
$jar->cookie_class(__PACKAGE__);
with
eval {$jar->cookie_class(__PACKAGE__)};
Enjoy!
来源:https://stackoverflow.com/questions/8594363/expected-token-not-present-error-in-my-apache-log