Nginx server cache settings example explain

  

This article describes, nginx as a web cache configuration, there is a need for friends to refer to it.

Use nginx as the web cache between the content source web server and the client.

Web Cache Solution: 1 Squid Cache 2 Nginx's proxy_cache

First, Nginx's proxy_cache consists of: proxy_cache related instruction set, fastcgi related instruction set

Proxy_cache which buffer will be used proxy_cache_path cache file storage path proxy_cache_methods cache HTTP method proxy_cache_min_users cache minimum usage proxy_cache_valid set different cache time for different return status code URL proxy_cache_key set cache key value, Nginx hash according to key value Cache

Install third-party ngx_cache_purge module: Delete the specified url cache Nginx web cache service

Step 1: ulimit -SHn 65535 Install pcre ./configure && make && Make install Install ngx_cache_purge Just unzip it Install

Code sample:

nginx ./configure --user=www --group=www --add-module=../ngx_cache_purge - -prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_model && make && make install

Step 2: Create 2 Cache Directories

Code Example:

mkdir -p /data0/proxy_temp_path mkdir -p /data0/proxy_cache_path

Steps Three: Configuring the cache of nginx.conf

Code example:

http{ ... proxy_temp_path ...; proxy_cache_path ...; server{ ... proxy_cache cache_name; proxy_cache_valid ... ; proxy_cache_key ...; } }

For the configuration of nginx cache, here are a few articles recommended, you can also refer to the following: nginx cache configuration example Nginx set static file cache time nginx cache local static file nginx five kinds Cache mode nginx cache static file method nginx proxy_cache cache configuration Nginx front-end proxy, cache

Next, fastcgi cache configuration.

Parameter Description:

fastcgi_cache Which cache is used by the cache fastcgi_cache_path Set the storage path of the cache file fastcgi_cache_methodes Set which HTTP methods to cache, default HTTP GET/HEAD method fastcgi_cache_min_users Set the minimum usage count of the cache, default 1 fastcgi_cache_valid Set different cache time for URLs returning different status codes fastcgi_cache_key Set the key value of the web cache, nginx hashes the cache according to the key value md5

Step 1: Create a cache directory: the cache path must be in the same Disk Partitions

Code Example:

mkdir -p /data0/fastcgi_temp_path mkdir -p /data0/fastcgi_cache_path

Step 2:

Code Example: Br>

Nginx configuration file http{ ... fastcgi_temp_path ...; fastcgi_cache_path ...; server{ ... fastcgi_cache cache_name; fastcgi_cache_valid ...; fastcgi_cache_key ...; } }

Copyright © Windows knowledge All Rights Reserved