When a popular page is not cached yet, every visitor who asks at that moment goes through to the backend. nginx can queue them behind the first one.
Add the lock where you already use proxy_cache:
location / {
proxy_pass http://127.0.0.1:9000;
proxy_cache app;
proxy_cache_valid 200 1m;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
add_header X-Cache-Status $upstream_cache_status;
}
The app zone comes from a proxy_cache_path line in the http block. With the lock on, only one request at a time is allowed to fetch a new item for a given cache key. The others wait for it to land in the cache. Test with nginx -t before you reload.
The waiting has limits, and that matters. After proxy_cache_lock_timeout a waiting request goes to the backend itself, and its answer is not cached. proxy_cache_lock_age lets one more request try if the first is taking too long. Both default to five seconds.
It helps for new items. For pages that expired and are being refreshed, look at proxy_cache_use_stale with updating too. I would skip it on responses that are never cacheable, where waiting gains nothing.
Further reading: nginx: ngx_http_proxy_module
Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause