Home >Operation and Maintenance >Nginx >Nginx Proxy Manager implements the deployment and configuration of multi-level cache

Nginx Proxy Manager implements the deployment and configuration of multi-level cache

WBOY
WBOYOriginal
2023-09-26 15:21:041448browse

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