使用nginx x-Accelcachingdynamic图像

我们试图caching请求到我们的nginx服务器上的图像。 即使图像是dynamic的,也会在短时间内频繁地请求相同的图像。 目前我们正试图用Nginxcachingx-accel请求来解决这个问题。

我们是否需要内部代理来启用这个function? 这甚至可能或者我们需要使用清漆? 如果可能的话,我们做错了什么?

我们的php代码:

$image = $images[$randomNumber]; header("Content-Type: application/octet-stream"); header('X-Accel-Expires: '. 'max'); header('Content-Disposition: attachment; filename='.$image.''); header('X-Accel-Redirect: /protected_files/'. $image); 

我们的网站启用configuration文件:

 proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:1000m inactive=60m; proxy_cache_key "$request_uri"; server { listen 80 default_server; root /usr/share/nginx/html; index index.php index.html index.htm; charset utf-8; location / { proxy_cache my_zone; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /protected_files { gzip off; internal; expires max; alias /xxx; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 

我们的默认configuration文件:

 user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 1024; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log off; error_log on; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }