Answer the question
In order to leave comments, you need to log in
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:
If you add an entry to the nginx config:
location ~* \.(jpg|jpeg|gif|png|swf|tiff|swf|flv|js|css)$ {
expires max;
}
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;
}
Answer the question
In order to leave comments, you need to log in
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;
}
}
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 questionAsk a Question
731 491 924 answers to any question