How to turn on browser cache for Nginx for all domains?

Created:

2016-12-18 06:54:19 UTC

Modified:

2017-08-08 13:16:36 UTC

0

Was this article helpful?


Have more questions?

Submit a request

How to turn on browser cache for Nginx for all domains?

Applicable to:

  • Plesk 12.5 for Linux

Question

How to turn on browser cache for nginx for all domains or server-wide?

For example turn on browser cache that can be added with the following complex directive:

location ~* \\.(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
try_files $uri @fallback;
}

Answer

Use the script from attachement. Run it by the following way:

  1. Download and unpack the archive

  2. Run the following commands for script set_directive.pl :

    # chmod +x set_directive.pl && perl set_directive.pl
  3. Please note, that script will change Nginx configuration for all domains simoultaneously.

Attachments:

Have more questions? Submit a request

4 Comments

  • 0
    Avatar
    Harry Sbr
    sed -i 's/9location/location/g' /var/www/vhosts/system/*/conf/vhost_nginx.conf

    :<
  • 0
    Avatar
    Vitaly Zhidkov

    @Harry, thank you, article was updated

  • 0
    Avatar
    Данил Трубицын

    root@ih461789:/# chmod +x set_directive.pl && ./set_directive.pl
    -bash: ./set_directive.pl: /usr/bin/perl^M: bad interpreter: No such file or directory

  • 0
    Avatar
    Artyom Baranov

    @Данил,

    Спасибо! :) Я поправил статью, теперь ошибки не будет и скрипт отработает.

Please sign in to leave a comment.