Rocky Linux 10 Nginx Cache Tuning

Web Servers

By Jennifer Webb

Updated on Aug 21, 2026

Rocky Linux 10 Nginx Cache Tuning

Learn Rocky Linux 10 Nginx cache tuning to speed up responses, reduce upstream load, and verify cache hits with clear commands.

Introduction

This tutorial shows how to tune Nginx proxy cache settings on Rocky Linux 10 for a dedicated-server deployment. You will install Nginx, configure a cache zone for proxied responses, and verify that repeated requests are served from cache instead of repeatedly hitting the upstream application.

The example uses a backend on 127.0.0.1:8080, which is a common pattern for a local application process behind Nginx on a dedicated server. By the end, you will have a working cache configuration and a way to confirm cache status with response headers.

Prerequisites

  • Rocky Linux 10 installed on the dedicated server
  • Root access or a normal administrative user with sudo privileges
  • Network access to install the Nginx package
  • A backend service reachable on 127.0.0.1:8080 for cache testing

Tutorial steps

First, install Nginx and confirm that the base service starts cleanly.

sudo dnf install -y nginx
sudo nginx -t
sudo systemctl enable --now nginx

Next, create the cache directory that Nginx will use for proxy cache files and make sure the SELinux context is applied correctly.

sudo mkdir -p /var/cache/nginx/proxy
sudo chown -R nginx:nginx /var/cache/nginx
sudo restorecon -Rv /var/cache/nginx

Now define the proxy cache settings and a simple reverse proxy server block. This configuration stores cached responses under /var/cache/nginx/proxy, enables cache locking, and exposes the cache state in the X-Cache-Status response header.

sudo tee /etc/nginx/conf.d/cache-tuning.conf >/dev/null <<'EOF'
proxy_cache_path /var/cache/nginx/proxy levels=1:2 keys_zone=app_cache:50m inactive=60m max_size=1g use_temp_path=off;

server {
    listen 80;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_cache app_cache;
        proxy_cache_valid 200 301 302 10m;
        proxy_cache_valid 404 1m;
        proxy_cache_lock on;
        proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
        add_header X-Cache-Status $upstream_cache_status always;
    }
}
EOF

Test the full configuration before reloading Nginx. This step is important because proxy cache directives are only effective when the configuration parses successfully.

sudo nginx -t

If the syntax test succeeds, reload Nginx to apply the cache tuning without interrupting the running service.

sudo systemctl reload nginx

Verification

Check the response headers from the local Nginx endpoint twice. The first request should normally produce a cache miss, and the second request should show a cache hit if the backend response is cacheable and the upstream service is reachable.

curl -I http://127.0.0.1/
curl -I http://127.0.0.1/

Confirm that the output includes X-Cache-Status with a valid cache state such as MISS on the first request and HIT on the repeated request. If the backend on 127.0.0.1:8080 is unavailable, Nginx cannot populate the cache and the verification will not demonstrate cache behavior correctly.

Troubleshooting

If sudo nginx -t fails, inspect the reported file and line number in /etc/nginx/conf.d/cache-tuning.conf. In this tutorial, syntax errors usually come from a missing semicolon, an unmatched brace, or an accidental edit inside the heredoc block.

If the cache directory causes permission or access errors, recheck ownership and SELinux labeling with the same commands used during setup. Nginx must be able to write to /var/cache/nginx/proxy for the cache zone to function.

If the header does not change from MISS to HIT, verify that the upstream service on 127.0.0.1:8080 is responding and that the response is cacheable under the configured status codes. A non-reachable backend will prevent a meaningful cache test.

Rollback

To undo the cache tuning, remove the custom Nginx configuration and reload the service. This restores Nginx to its previous state without the proxy cache settings from this tutorial.

sudo rm -f /etc/nginx/conf.d/cache-tuning.conf
sudo nginx -t
sudo systemctl reload nginx

If you also want to remove the local cache storage, delete the cache directory after confirming it is no longer needed.

sudo rm -rf /var/cache/nginx/proxy

Conclusion

You have tuned Nginx cache behavior on Rocky Linux 10 for a dedicated server, verified the configuration, and confirmed how to check for cache hits through response headers. This gives you a practical way to reduce upstream load and validate that Nginx cache tuning is working as intended on the server.

Rocky Linux 10 Nginx Cache Tuning - HostnExtra