A
A
Angel12017-01-13 17:57:55
css
Angel1, 2017-01-13 17:57:55

How to make static browser caching on NGINX + YII2?

There is a site on Yii2 which costs on NGINX.
Google page speed test swears that static is not cached, but the browser itself shows something else:
2f1ceed18c3f4f869ba0e29cfe7390b6.png
If you add an entry to the nginx config:

location ~* \.(jpg|jpeg|gif|png|swf|tiff|swf|flv|js|css)$ {
      expires max;
   }

Then when these files are connected, it gives out 404, I think this is due to the fact that I have the following entries in the config:
location / {
                if ($request_uri ~ "^/backend"){
                        rewrite ^/backend/(.*)$ /backend/web/$1;
                }
                if ($request_uri !~ "^/backend"){
                        rewrite ^(.*)$ /frontend/web/$1;
                }
        }

        location /frontend/web/ {
                if (!-e $request_filename){
                        rewrite ^(.*)$ /frontend/web/index.php;
                }
        }
        location /backend/web/ {
                if (!-e $request_filename){
                        rewrite ^(.*)$ /backend/web/index.php;
                }
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

Can you please tell me where to insert expires max to cache statics?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Angel1, 2017-01-13
@Angel1

Here is the rule in which you need to enter caching for statics, but I don’t know how to do it.

location /frontend/web/ {
                if (!-e $request_filename){
                        rewrite ^(.*)$ /frontend/web/index.php;
                }
        }

M
Maxim Timofeev, 2017-01-13
@webinar

I am sure that Google swears at caching not on the server side, nginx has nothing to do with it. Google has no idea what is cached on your server and what is not.
You need to cache images and other things in the browser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question