load balancing and caching combination problem
Maxim Dounin
mdounin at mdounin.ru
Mon Aug 31 14:18:23 MSD 2009
Hello!
On Mon, Aug 31, 2009 at 04:57:01AM -0400, fredericsidler wrote:
> I just installed nginx 0.8.11 in order to use the $upstream_cache_status variable.
>
> I can see now in the logs that my URLs (ics feed URLs) are cached and retrieved from the cache (MISS, HIT, EXPIRED) based on my caching parameters.
>
> But, it only works when
> proxy_ignore_headers Cache-Control;
> proxy_ignore_headers Expires;
>
> are used and left uncommented. I have read in the forums that this shouldn't be use in production. So what should I do next to be able to comment these parameters and get the result I'm expected.
Directive proxy_ignore_headers instruct nginx to *ignore* headers
in question got from upstream. And as you have Cache-Control
returned by your upstream - nginx honors it unless
proxy_ignore_headers specified. There is nothing wrong here.
Best solution would be to fix upstream server to return cache-related
headers you want. If you can't do that for some reason - the only
way is to use proxy_ignore_headers.
> I tried to set the Expires header by using set_proxy_header, but no headers are added to my file. Here is my configuration file and the headers of one the ICS file
Directive proxy_set_header sets headers sent to upstream, it's
completely unrelated. There is no way to alter upstream response
before caching it.
Maxim Dounin
>
> nginx.conf
>
> user www-data;
> worker_processes 4;
>
> error_log /var/log/nginx/error.log;
> pid /var/run/nginx.pid;
>
> events {
> worker_connections 4096;
> }
>
> http {
> include /etc/nginx/mime.types;
> default_type application/octet-stream;
>
> log_format fbcal '$remote_addr - $remote_user [$time_local] '
> '"$request" $status $body_bytes_sent '
> '"$http_referer" "$http_user_agent"'
> '"$upstream_cache_status"';
>
> access_log /var/log/nginx/access.log fbcal;
>
> sendfile on;
>
> keepalive_timeout 30;
> tcp_nodelay on;
>
> include /etc/nginx/app-servers.include;
>
> proxy_cache_path /var/www/fbcaldotcom/cache levels=1:2 keys_zone=one:10m;
> proxy_temp_path /temp/cache;
>
> server {
> listen 80;
>
> if ( $remote_addr = 127.0.0.1 ) {
> rewrite ^(.*)$ /500.html last;
> return 302;
>
> }
>
> location / {
> proxy_pass http://backend;
>
> proxy_cache one;
> proxy_cache_key backend$request_uri;
> proxy_cache_valid 200 3h;
> proxy_cache_use_stale error timeout invalid_header;
> # proxy_ignore_headers Cache-Control;
> # proxy_ignore_headers Expires;
>
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
> error_page 500 501 = /500.html;
> error_page 502 503 504 = /502.html;
> }
>
> location /500.html {
> root /var/www/nginx-default;
> }
>
> location /502.html {
> root /var/www/nginx-default;
> }
>
> }
>
> }
>
> curl -I
>
> HTTP/1.1 200 OK
> Server: nginx/0.8.11
> Date: Mon, 31 Aug 2009 08:41:57 GMT
> Content-Type: text/calendar; charset=utf-8
> Connection: keep-alive
> X-Powered-By: PHP/5.2.4-2ubuntu5.7
> Content-Disposition: attachment; filename="fbCal-Events.ics"
> Cache-Control: max-age=10
> Content-Length: 80450
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,5392,5392#msg-5392
>
>
More information about the nginx
mailing list