nginx serving wrong website under proxy_cache

Payam Chychi pchychi at gmail.com
Wed Apr 29 10:40:03 MSD 2009


2009/4/28 Igor Sysoev <is at rambler-co.ru>:
> On Tue, Apr 28, 2009 at 07:27:00PM -0700, Payam Chychi wrote:
>
>> hey guys,
>>
>> So I had 3 sites configured to use caching on my nginx box (tried with
>> .50, 52 and 53 build) however of the three websites kept redirecting
>> me to the first site that I was doing caching for.
>>
>> Example Sites:
>> 0.0.0.1
>> 0.0.0.2
>> 0.0.0.3
>>
>> HTTP config very similar to this only each utilize a different
>> "listen" ip address and each site has a different Backend 'Origin" ip:
>>
>> # HTTP LB
>>  upstream LB_HTTP_0.0.0.1 {
>>  server x.x.x.x:80;
>>  }
>>
>>     server {
>>
>>         listen       0.0.0.1:80;
>>         server_name  website_0.0.0.1;
>>
>>          access_log      /var/log/nginx/any.website_0.0.0.1.access_log main;
>>          error_log       /var/log/nginx/any.website_0.0.0.1.error_log info;
>>
>>         error_page  404  /404.html;
>>         location = /404.html {
>>             root   html;
>>         }
>>         error_page  404 500 502 503 504  /50x.html;
>>         location = /50x.html {
>>             root   html;
>>         }
>>
>>          location / {
>>          proxy_intercept_errors on;
>>          proxy_pass              http://LB_HTTP_0.0.0.1;
>>          proxy_cache             one;
>>          proxy_cache_key         backend$request_uri;
>
> Do you have the same
>
>           proxy_cache_key         backend$request_uri;
>
> for all three sites ? You need something like this:
>
>           proxy_cache_key         0.0.0.1$request_uri;
>
> Or you may create several caches:
>
> proxy_path /path/to/cache1  keys_zone=cache1:10m;
>
>>          proxy_cache_valid       200  1h;
>>          proxy_cache_valid       404 5m;
>>          proxy_cache_use_stale   error timeout invalid_header;
>>          }
>> }
>>
>>
>> When browsing to 0.0.0.1, everything was fine
>> going to 0.0.0.2 or 0.0.0.3 or any other ip for that matter in the
>> same class C "/24" it would redirect you to the 0.0.0.1 config which
>> would then proxy-pass the data back to the origin belonging to the
>> 0.0.0.1 config
>>
>> Anyone seen this issue at all?
>> Once i commented all proxy_cache and restarted nginx, problem went away.
>>
>> Note that i even tried deleting /etc/nginx-cache/* and recreating
>> it... did not help
>>
>> Thanks,
>> --
>> Payam Tarverdyan Chychi
>> Network Security Specialist / Network Engineer
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
>
>

Hey Igor,

That was the problem... I was using "backend" for each of the configs
so it was confused. Which would you recommend for stability and
scalability, attaching a dynamic $ to the proxy_cache_key or creating
a separate cache for each site that requires caching?
 keep in mind that id like to support up to 500 sites per box if
possible, each doing anywhere from 1mbps to +10mbps

Thanks,
-- 
Payam Tarverdyan Chychi
Network Security Specialist / Network Engineer





More information about the nginx mailing list