E
E
EVOSandru62020-06-23 02:42:49
Nginx
EVOSandru6, 2020-06-23 02:42:49

How to cache only design assets in Laravel using nginx?

Next block: location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$
Caches all resources with the specified extensions.

I would like only resources from the /public/build folder to be juggled

. there are dynamic pictures, the variability of which is quite frequent.

I refer to these resources ala:

/build/front/images/1.png
/build/admin/css/app.css

server
{
    listen 80;
    server_name www.domen.com;

    index index.php index.html;
    root /var/www/public;

    location / {
        try_files $uri /index.php?$args;
    }

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
    log_not_found off;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-23
@dodo512

Above the \.(jpg|jpeg|gif|css|png|js|ico|html)$ block, add a block with ^/build/.*\.(jpg|jpeg|gif|css|png|js|ico|html) $

server
{
  ... 

  location ~* ^/build/.*\.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
    log_not_found off;
  }
  
  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;

    log_not_found off;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question