Getting built in 404 instead of my custom one

Ian M. Evans ianevans at digitalhit.com
Tue Oct 9 08:26:31 UTC 2012


On Tue, October 9, 2012 3:57 am, Igor Sysoev wrote:
> On Mon, Oct 08, 2012 at 11:51:21PM -0400, Ian M. Evans wrote:
>> On Mon, October 8, 2012 10:55 pm, Ian M. Evans wrote:
>> [snip]
>>
>> > hmm, disabled the fastcgi cache and it served my error file okay.
>> enabled
>> > the cache and it served the nginx internal 404.
>> >
>> > Here's our cache setup:
>> >
>> > fastcgi_cache_path /var/lib/nginx/fastcgicache levels=1:2
>> > keys_zone=MYCACHE:5m inactive=2h max_size=1g loader_files=1000
>> > loader_threshold=2000;
>> > map $http_cookie $no_cache { default 0; ~SESS 1; }
>> > fastcgi_cache_key "$scheme$request_method$host$request_uri";
>> > add_header X-My-Cache $upstream_cache_status;
>> >
>> > map $uri $no_cache_dirs {
>> >    default 0;
>> >    ~^/(?:phpMyAdmin|rather|poll|webmail|skewed|blogs|galleries|pixcache)
>> > 1;
>> > }
>> >
>> > Should I toss the custom 404 into a non-cached subdir?
>> >
>>
>> that didn't work.
>>
>> It's definitely the fastcgi cache interfering with the php-parsed custom
>> error page.
>>
>> I'm scratching my head here.
>>
>> My fastcgi.conf contains this additional cache info:
>>
>> fastcgi_cache MYCACHE;
>> fastcgi_keep_conn on;
>> fastcgi_cache_bypass $no_cache $no_cache_dirs;
>> fastcgi_no_cache $no_cache $no_cache_dirs;
>> fastcgi_cache_valid 200 301 5m;
>> fastcgi_cache_valid 302 5m;
>> fastcgi_cache_valid 404 1m;
>> fastcgi_cache_use_stale error timeout invalid_header updating http_500;
>> fastcgi_ignore_headers Cache-Control Expires;
>> expires epoch;
>> fastcgi_cache_lock on;
>>
>> I thought adding:
>>
>> map $uri $no_cache { default 0;
>> /dhe404.shtml 1;
>> }
>>
>> in my nginx.conf would do the trick, but nope. How can I stop the
>> fastcgi_cache from handling the custom error page?
>
> The issue is in fastcgi_cache_key:
> fastcgi_cache_key "$scheme$request_method$host$request_uri";
>
> It always uses client original $request_uri. Try:
> fastcgi_cache_key "$scheme$request_method$host$uri?$args";
>

Thanks, Igor. It sort of worked. I'm now getting the custom 404, but it's
a cached version of the custom 404 php file.

That is, my custom 404 tells the visitor:

"Hmmmm
the page you're looking for [ /zap.shtml ] doesn't seem to be on
our site. [etc, etc]" If I then do another file name that doesn't exist,
say, test1.shtml, I'm getting a cached version of the 404 as instead of
saying test1.shtml, it still says "Hmmmm
the page you're looking for [
/zap.shtml ] doesn't seem to be on our site."

So, though it's now serving the custom 404, it's still serving a cached
version. So I guess I need a way to turn off caching for the custom 404
file. Just tried another one and, of course, got a cached 404 that someone
else had just tried.



More information about the nginx mailing list