Home Operation and Maintenance Nginx How to enable or disable nginx cache

How to enable or disable nginx cache

Dec 25, 2020 am 10:42 AM
nginx cache

How to enable or disable nginx cache

Sometimes when we are debugging the website program, we will encounter the problem that the code modification is invalid due to the browser's cache. At this time, we must force refresh to clear the cache, which is very of inconvenience.

(Learning video sharing: Programming video)

If we disable nginx cache, let the browser go to the server to request the file every time instead of reading it in the browser It will be much more convenient to retrieve the cached files.

After the program is debugged and goes online, you can turn on nginx cache to save the server's bandwidth traffic, reduce some requests, and reduce the pressure on the server.

Achieve the switch effect by configuring the nginx configuration file /usr/local/nginx/conf/nginx.conf

1. Enable cache

1

2

3

4

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { 

    #设置缓存上面定义的后缀文件缓存到浏览器的生存时间

  expires   3d;

}

Copy after login

2. Disable Cache

1

2

3

4

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {

    #禁止缓存,每次都从服务器请求

  add_header Cache-Control no-store;

}

Copy after login

Related recommendations:nginx tutorial

The above is the detailed content of How to enable or disable nginx cache. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot tools Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

How to allow external network access to tomcat server

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

What are the nginx start and stop commands?

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

How to solve the problem of nginx when accessing the website

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

Welcome to nginx!How to solve it?

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

How to deploy nodejs project to server

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

How to register phpmyadmin

How to communicate between docker containers How to communicate between docker containers Apr 07, 2024 pm 06:24 PM

How to communicate between docker containers

See all articles