search
HomeOperation and MaintenanceNginxNginx Proxy Manager implements the deployment and configuration of multi-level cache

Nginx Proxy Manager实现多级缓存的部署与配置

Nginx Proxy Manager is an open source reverse proxy server that can implement multi-level cache deployment and configuration. Through reasonable configuration, the performance and access speed of the website can be improved.

1. Install Nginx Proxy Manager
First, we need to install Nginx Proxy Manager. You can install it through the following steps:

  1. Update system packages: sudo apt update
  2. Install Nginx: sudo apt install nginx
  3. Install Node.js and npm: sudo apt install nodejs npm
  4. Download and install Nginx Proxy Manager: git clone https://github.com/jc21/nginx-proxy-manager.git
    cd nginx-proxy-manager
    npm install
    npm run db:seed

2. Configure Nginx Proxy Manager

  1. Modify the configuration file
    Open the configuration file of Nginx Proxy Manager: sudo nano /etc/nginx/sites-available/default
    Add the following configuration in the server section of the file:

    location / {
       proxy_pass http://127.0.0.1:8080;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
    }

    Change 127.0.0.1:8080 in the above configuration to the upstream server address you actually use and port.

  2. Configure cache
    Open the cache configuration file of Nginx Proxy Manager: sudo nano /etc/nginx/nginx.conf
    Add the following configuration in the http section:

    proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m;
    proxy_cache_key "$scheme$request_method$host$request_uri";
    proxy_cache_valid any 10m;
    
    server {
       ...
       
       location / {
          proxy_cache my_cache;
          proxy_cache_valid 200 301 302 10m;
          proxy_cache_valid any 10s;
          proxy_cache_min_uses 1;
          proxy_cache_background_update on;
          proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
          proxy_cache_lock on;
          proxy_cache_lock_timeout 5s;
          proxy_pass http://127.0.0.1:8080;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
       }
       
       ...
    }

    Replace /path/to/cache in the above configuration with the path where you actually want the cache to be stored.

3. Testing and Effect
Restart Nginx: sudo systemctl restart nginx
Now, you can access the public IP address of the server through the browser and pass the request to the upstream server and caches the response. This way, when multiple users request the same resource, Nginx Proxy Manager will serve the response directly from the cache instead of re-requesting the upstream server.

4. Implement multi-level caching
If your architecture requires a higher level of caching, you can configure multiple Nginx Proxy Manager instances and connect them.

For example, you can set up an Nginx Proxy Manager instance as a front-end cache server and forward requests to another Nginx Proxy Manager instance, which acts as an upstream server. This way, the front-caching server will cache the response requested from the upstream server and serve the response directly from the cache on subsequent requests. Only when there is a cache miss will the front cache server request the upstream server.

The method of configuring multi-level cache is similar to configuring a single cache. You only need to configure the address and port of the pre-caching server to the address and port of the upstream server.

5. Summary
Through Nginx Proxy Manager, we can easily implement the deployment and configuration of multi-level cache. Properly configuring the cache can effectively improve the performance and access speed of the website and reduce the load on the upstream server. Hope the above content is helpful to you.

The above is the detailed content of Nginx Proxy Manager implements the deployment and configuration of multi-level cache. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 14, 2025 pm 01:03 PM

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.

How to close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure nginx in WindowsHow to configure nginx in WindowsApr 14, 2025 pm 12:57 PM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor