


Use nginx proxy_cache to configure website cache underpinning nginx fastcgi cache nginx cache configuration nginx file cach
As we all know, nginx proxy_cache can cache the requested response, playing a role similar to CDN. It even provides more functions than CDN. It can also be used to cache the underlying data. When the background tomcat hangs, nginx will directly cache it. The underlying data in is returned to the user.
Directly paste the detailed configuration
upstream tomcat_localhost {
//Be careful not to set the timeout too long here
server 127.0.0.1:8080 weight=10 max_fails=1 fail_timeout=1s;
}
1.nginx cache Space configuration, this configuration can be defined above the server in the nginx configuration file
#proxy_cache_path: The cache file path of the proxy cache, /export/Data/huishou.jd.local This directory must be created in advance, otherwise the configuration file detection will Failed, and the directory cannot be deleted. The cache disappears after deletion
# levels=1:2 nginx will create two more directories under the cache file path configured above. The first-level directory is named with one character, and the second-level directory is named It is 2 characters
#keys_z max_size=100m Define the cache name and cache size. The cache name will be used in the location below. The cache size can be set based on your own server memory and the size of the content that the system needs to cache
# inactive=1d is the validity time of the cache file. After the cache reaches the set time, it will be removed from the cache path regardless of whether it is in use, and then return to the source to obtain new data and generate the cache file
proxy_cache_path /export/Datal/cache levels=1 :2 keys_z max_size=300m inactive=1d;
2.nginx cache bottom interception configuration, which is configured in a specific location
location / {
#Configure the cache space name defined above, required configuration
proxy_cache my_cache ;
#Set the cache key, which can also be customized according to the parameters in the URL; $args represents all parameters, or you can use one of them, for example: $arg_name, which means only taking the name parameter in the parameter list, here Can be configured flexibly, required configuration
proxy_cache_key $host$uri$is_args$args;
#Set the request URL that bypasses the cache, that is, if the URL contains the value of this configuration, the request will not obtain data from the cache. Must be configured
proxy_cache_bypass $arg_noCache;
#Set the cache time based on the response code. After this time, even if there is cached data in the cache file, nginx will return to the source to request new data. The value here can also be controlled based on the Cache-Control cache time set in the header of the response. The setting in the header has the highest priority. If the cache time is not set here and in the header, nginx will not generate a cache file. Must be configured. If there is no configuration here, there must be settings in the header.
proxy_cache_valid 200 1m;
#This is the bottom configuration. The old one is better than the error. When nginx requests the background server to report an error, if the configuration is returned Error response code, nginx directly retrieves the old data in the cache file and returns it to the user, using the required configuration
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
#Cache concurrency lock, only when the nginx cache does not hit One request goes back to the source tomcat to request data, and other requests will wait. Non -optional configuration oProxy_cache_lock on;
Proxy_cache_lock_timeout 1s;
Proxy_pass
Localhost; }
3. Nginx's cache bottom The configuration is complete. During the validity period of the cache file, even if the background tomcat hangs, the cached pages or interfaces can still provide services normally.
The above introduces the use of nginx proxy_cache for website cache backing configuration, including nginx and cache aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP
