E
E
egor_spk2015-08-13 14:23:30
Nginx
egor_spk, 2015-08-13 14:23:30

Why might the browser cache not work through nginx?

For some reason, the HTTP response does not contain the expiration date of static resources, namely the ".gif" and ".jpg" files.
".png" works:

Cache-Control:max-age=604800
Cache-Control:public
Connection:keep-alive
Date:Thu, 13 Aug 2015 11:04:55 GMT
ETag:"55c8b874-1cd0"
Expires:Thu, 20 Aug 2015 11:04:55 GMT
Last-Modified:Mon, 10 Aug 2015 14:43:00 GMT
Pragma:public
Server:nginx/1.4.6 (Ubuntu)

Maybe something in the nginx config is wrong:
server {
        location ~ \.php$ {
                try_files $uri =404;
                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 ~* \/\.ht {
                deny all;
        }
        location ~* ^\/(classes|errors\/logs|sys\-temp|cache|xmldb|static|packages) {
                deny all;
        }
        location ~* (\/for_del_connector\.php|\.ini|\.conf)$ {
                deny all;
        }
        location ~* ^(\/files\/|\/images\/) {
                try_files $uri =404;
        }
        location ~* ^\/images\/autothumbs\/ {
                try_files $uri @autothumbs =404;
        }
        location @autothumbs {
                rewrite ^\/images\/autothumbs\/(.*)$ /autothumbs.php?img=$1$query_string last;
        }
        location @clean_url {
                rewrite ^/(.*)$ /index.php?path=$1 last;
        }
        location @dynamic {
                try_files $uri @clean_url;
        }
             location / {
                rewrite ^\/robots\.txt /sbots.php?path=$1 last;
                rewrite ^\/sitemap\.xml /sitemap.php last;
                rewrite ^\/\~\/([0-9]+)$ /tinyurl.php?id=$1 last;
                rewrite ^\/(udata|upage|uobject|ufs|usel|ulang|utype|umess|uhttp):?(\/\/)?(.*)? /releaseStreams.php?scheme=$1&path=$3 last;
                rewrite ^\/(.*)\.xml$ /index.php?xmlMode=force&path=$1 last;
                rewrite ^(.*)\.json$ /index.php?jsonMode=force&path=$1 last;
                if ($cookie_umicms_session) {
                        error_page 412 = @dynamic;
                        return 412;
                }
                if ($request_method = 'POST') {
                        error_page 412 = @dynamic;
                        return 412;
                }
        }
        location ~* \.js$ {
                rewrite ^\/(udata|upage|uobject|ufs|usel|ulang|utype|umess|uhttp):?(\/\/)?(.*)? /releaseStreams.php?scheme=$1&path=$3 last;
                try_files $uri =404;
        }
        location ~* \.(ico|jpg|jpeg|png|gif|swf|css)$ {
                access_log off;
                expires 7d;
                add_header Pragma public;
                add_header Cache-Control "public";
                try_files $uri =404;

        }
}

CMS: UMI.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
egor_spk, 2015-08-13
@egor_spk

Arik was right.
Removed "\/images\/" from

location ~* ^(\/files\/|\/images\/) {
                try_files $uri =404;
        }

and everything worked.

A
Arman, 2015-08-13
@Arik

Do the files in the same folder really exist? just two locations at the same time, I can’t seem to work out

T
TyzhSysAdmin, 2015-08-13
@POS_troi

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
        root /path_to_root/;
        access_log off;
        expires 7d;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question