The following is a tutorial on nginx reverse proxy cache:
-
Install nginx:
sudo apt update sudo apt install nginx
-
Configure reverse proxy:
Open nginx configuration file:sudo nano /etc/nginx/nginx.conf
-
Add the following configuration in the
http
block to enable caching:http { ... proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; proxy_cache_key "$scheme$request_method$host$request_uri"; proxy_cache_valid 200 302 10m; proxy_cache_valid 404 1m; ... }
-
proxy_cache_path
: Specify the cache path and related parameters. -
proxy_cache_key
: Define the format of the cache key. -
proxy_cache_valid
: Set response code and cache time.
-
-
Configure the reverse proxy server:
Add the following configuration in theserver
block:server { ... location / { proxy_pass proxy_set_header Host $host; proxy_cache my_cache; proxy_cache_valid 200 302 10m; proxy_cache_valid 404 1m; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; } ... }
-
proxy_pass
: Specify the address of the backend server. -
proxy_set_header
: Set request header information. -
proxy_cache
: Specify the cache area used. -
proxy_cache_valid
: Set response code and cache time. -
proxy_cache_use_stale
: Specifies that stale responses are allowed when updating the cache.
-
- Save and close the configuration file.
-
Check whether nginx configuration is correct:
sudo nginx -t
-
Reload nginx configuration:
sudo systemctl reload nginx
Now, nginx has configured reverse proxy cache. It will cache the response of the backend server and serve the cached response directly on the next request, reducing the load on the backend server and improving performance.
Please adjust the cache configuration and proxy server address according to your actual needs. Hope this tutorial is helpful!
The above is the detailed content of nginx reverse proxy caching tutorial.. For more information, please follow other related articles on the PHP Chinese website!

You may encounter the “this build of Vanguard is out of compliance” issue when attempting to launch Valorant on Windows 11. Why does the error message appear? How to get rid of the error message? This post from php.cn gives details.

NVIDIA GeForce RTX 40 series GPU might not be a new thing to you. Compared with other top graphics cards, many of you may pay more attention to mid-end mainstream RTX 4050 for its acceptable price. Read through this guide from php.cn Website to get d

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Do you know how to reinstall pre-installed software in Windows 11 if you need to do this? In this post, we will introduce two easy ways. In addition, if you want to recover files on your Windows computer, you can try php.cn Power Data Recovery.

Windows Desktop or File Explorer or folder will automatically refresh itself when you make some changes to it. However, some Windows 11/10 users report that they encounter the “desktop and file folders do not refresh automatically” issue. This post f

When you try to install a program on Windows 11/10, you may fail to install it and receive an error message - there is a problem with this Windows installer package. This post from php.cn helps you to fix it.

When you run antivirus software on your device, you likely expect it to scan all files and folders for viruses. However, one question arises: can antivirus scan encrypted files? This inquiry delves into the realm of security versus privacy. php.cn So

How to download HDMI video drivers on Windows? How to update HDMI drivers to the latest versions. You can find the ways here. In addition, you can try php.cn Power Data Recovery to get your lost and deleted files back if necessary.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.