Cache by mime type

burn nginx-forum at
Fri Jul 20 17:47:35 UTC 2012

can you elaborate on how to implement it? For me, it seems to cache html
as well (I'm checking saved files). Here's what I come up with:


user  nginx;
worker_processes  8;
worker_rlimit_nofile 100000;
error_log   /var/log/nginx/error.log;
pid        /var/run/;
events {
    worker_connections  1024;
    use epoll;
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local]
"$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log combined;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  65;
    limit_conn_zone   $binary_remote_addr  zone=addr:10m;
    map $http_content_type $no_proxy {
        default         0;
        "~*image/"      1;
    proxy_cache_path  /tmp/nginx/cache/image  levels=1:1:2 
    proxy_temp_path  /tmp/nginx/temp;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/vhosts/*;


server {
    listen       8082;
    charset utf-8;
    access_log  /var/log/nginx/ combined;
    error_log /var/log/nginx/;
    location / {
        root   /var/www/html/;
        index  index.php;
        try_files $uri @apache;
    location /forum {
        root   /var/www/html/;
        index  index.php;
        try_files $uri @apache;
    location /gallery {
        root   /var/www/html/;
        index  index.php;
        try_files $uri @apache;
    location ~ ^.*\.php$ {
    location @apache {

proxy_cache image;
proxy_cache_use_stale updating;
proxy_cache_valid 7d;
proxy_cache_bypass $no_proxy;
proxy_connect_timeout 59s;
proxy_send_timeout   600;
proxy_read_timeout   600;
proxy_buffer_size    64k;
proxy_buffers     16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_pass_header Set-Cookie;
proxy_redirect     off;
proxy_hide_header  Vary;
proxy_set_header   Accept-Encoding '';
proxy_ignore_headers Cache-Control Expires;
proxy_set_header   Referer $http_referer;
proxy_set_header   Host   $host;
proxy_set_header   Cookie $http_cookie;
proxy_set_header   X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Posted at Nginx Forum:,228786,228794#msg-228794

More information about the nginx mailing list