Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Disadvantages and advantages of Nginx caching

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the disadvantages and advantages of Nginx cache". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the disadvantages and advantages of Nginx cache".

Both Nginx caches have basically the same advantages and disadvantages:

Disadvantage 1: dynamic links with parameters, such as read.php?id=1, are not supported, because the Nginx cache only holds the file name, so this link is only saved as read.php under the file system, so that users will return incorrect results when they visit read.php?id=2. At the same time, the home page and secondary directory http://www.sudone.com/download/ in the form of http://www.sudone.com/ are not supported, because the Nginx cache is very honest and will write such a request to the file system according to the link, which is obviously a directory, so the save failed. These situations need to be written in rewrite in order to save them correctly.

The disadvantage is that there is no mechanism for cache expiration and cleaning inside the 2:Nginx cache, and these cached files will be stored on the machine *. If there are a lot of things to cache, it will overwhelm the entire hard disk space. To do this, you can use a shell script to clean up regularly, and you can write dynamic programs such as php to do real-time updates.

Disadvantage 3: only 200 status codes can be cached, so the status codes returned by the backend will not be cached. If a pseudo-static link with a large number of visits is deleted, it will continue to penetrate and cause a lot of pressure on the backend.

The disadvantage is that 4:Nginx does not automatically choose memory or hard disk as the storage medium, everything is determined by configuration. Of course, there is an operating system-level file caching mechanism in the current operating system, so there is no need to worry too much about io performance problems caused by large concurrent reads on the hard disk.

The disadvantage of Nginx traditional cache is also different from other caching software such as squid, so it can also be regarded as its advantage. In production applications, it is often used as a partner with squid, squid for belt? Links are often unstoppable, and Nginx can block their access, such as http://sudone.com/? And http://sudone.com/ will be treated as two links on squid, so it will cause two penetrations, while Nginx will only be saved once, no matter whether the link becomes http://sudone.com/?1 or http://sudone.com/?123, it cannot be cached through Nginx, thus effectively protecting the backend host.

Nginx cache will be very honest to save the form of links to the file system, so that for a link, you can easily check its cache state and content on the cache machine, and it can also be easily used with other file managers such as rsync, etc., it is completely a file system structure.

Both of these traditional caches can save files to / dev/shm under linux, and I usually do the same, so I can use system memory for caching, which makes it much faster to clean up expired content. When using / dev/shm/, in addition to pointing the tmp directory to the partition / dev/shm, if there are a large number of small files and directories, modify the number of inode and * capacity of this memory partition:

Mount-o size=2500M-o nr_inodes=480000-o noatime,nodiratime-o remount / dev/shm

The above command is used on a machine with 3G memory, because / dev/shm default * * memory is 1500m, this command increases it to 2500m, and the number of inode in shm system may not be enough by default, but the interesting thing is that it can be adjusted at will, which is 480000 conservative, but it is basically enough.

Thank you for reading, the above is the content of "the disadvantages and advantages of Nginx cache". After the study of this article, I believe you have a deeper understanding of the disadvantages and advantages of Nginx cache, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report