Bird
Raised Fist0
Nginxdevops~20 mins

Purging cached content in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cache Purge Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command to purge cache in Nginx?
You run the following command to purge a cached file in Nginx cache directory:
rm -rf /var/cache/nginx/*

What is the expected result?
Nginx
rm -rf /var/cache/nginx/*
AThe command deletes only files named '*' literally.
BOnly cached files older than 7 days are deleted.
CThe command returns an error because of missing sudo privileges.
DAll cached files in /var/cache/nginx/ are deleted immediately.
Attempts:
2 left
💡 Hint
Think about what the wildcard * means in shell commands.
❓ Configuration
intermediate
2:00remaining
Which Nginx configuration snippet enables cache purging via HTTP request?
You want to allow cache purging by sending a special HTTP request to Nginx. Which configuration snippet correctly enables this?
Nginx
location ~ ^/purge(/.*) {
    allow 127.0.0.1;
    deny all;
    proxy_cache_purge my_cache $1;
}
A
location ~ ^/purge(/.*) {
    allow 127.0.0.1;
    deny all;
    proxy_cache_purge my_cache $1;
}
B
location /purge/ {
    proxy_cache_purge my_cache $request_uri;
    allow all;
}
C
location /purge/ {
    deny 127.0.0.1;
    allow all;
    proxy_cache_purge my_cache $request_uri;
}
D
location /purge/ {
    proxy_cache_bypass my_cache $request_uri;
    allow 127.0.0.1;
    deny all;
}
Attempts:
2 left
💡 Hint
Remember to restrict purge access to localhost only.
❓ Troubleshoot
advanced
2:00remaining
Why does the cache not purge after sending a PURGE request?
You configured Nginx to allow PURGE requests to clear cache, but after sending a PURGE request, the cache remains. What is the most likely cause?
AThe PURGE request was sent from an unauthorized IP address.
BThe cache directory is empty, so nothing to purge.
CThe PURGE method is not allowed in the Nginx configuration.
DThe proxy_cache_path directive is missing.
Attempts:
2 left
💡 Hint
Check IP restrictions in your purge location block.
🔀 Workflow
advanced
2:30remaining
What is the correct workflow to safely purge a specific cached URL in Nginx?
You want to purge the cached content for URL /images/logo.png without affecting other cached files. What is the correct sequence of steps?
A2,4,1,3
B2,1,3,4
C1,2,3,4
D4,2,1,3
Attempts:
2 left
💡 Hint
Think about verifying config before purging and checking logs after.
✅ Best Practice
expert
3:00remaining
Which practice is best for purging cached content in a high-traffic Nginx environment?
In a busy production environment, what is the best practice to purge cached content without causing downtime or performance issues?
ADisable caching temporarily during purging to avoid stale content.
BManually delete all cache files daily with rm -rf to ensure freshness.
CUse HTTP PURGE requests restricted by IP and automate purging only for changed URLs.
DReload Nginx after every PURGE request to apply changes immediately.
Attempts:
2 left
💡 Hint
Think about minimizing impact and targeting only needed cache entries.

Practice

(1/5)
1. What is the main purpose of purging cached content in nginx?
easy
A. To remove specific cached files so fresh content is served
B. To increase the cache size automatically
C. To disable caching completely
D. To restart the nginx server

Solution

  1. Step 1: Understand caching in nginx

    Caching stores copies of content to serve faster responses.
  2. Step 2: Understand purging purpose

    Purging removes specific cached files to update content without restarting nginx.
  3. Final Answer:

    To remove specific cached files so fresh content is served -> Option A
  4. Quick Check:

    Purging = Remove cached files [OK]
Hint: Purging means deleting cached files to refresh content [OK]
Common Mistakes:
  • Confusing purging with disabling cache
  • Thinking purging restarts nginx
  • Assuming purging increases cache size
2. Which of the following is the correct syntax to enable cache purging in an nginx location block?
easy
A. proxy_cache_purge true;
B. proxy_cache_purge off;
C. proxy_cache_purge enable;
D. proxy_cache_purge mycache;

Solution

  1. Step 1: Recall nginx directive syntax

    Directives use the format: directive_name value; with zone name for cache purging.
  2. Step 2: Identify correct value for enabling purge

    Enabling uses zone name 'mycache' not 'enable', 'true', or 'off'.
  3. Final Answer:

    proxy_cache_purge mycache; -> Option D
  4. Quick Check:

    Enable purge = proxy_cache_purge mycache; [OK]
Hint: Use the zone name to enable cache purging in nginx [OK]
Common Mistakes:
  • Using 'enable' or 'true' instead of the zone name
  • Forgetting the semicolon at the end
  • Setting proxy_cache_purge to 'off' by mistake
3. Given this nginx config snippet:
location /purge/ {
    allow 192.168.1.0/24;
    deny all;
    proxy_cache_purge mycache;
}

What happens when a client from IP 192.168.1.10 sends a PURGE request to /purge/page1?
medium
A. The cached content for /purge/page1 is removed
B. The request is denied due to IP restriction
C. The cache is cleared for all pages
D. The server returns a 404 error

Solution

  1. Step 1: Check IP access rules

    Allow 192.168.1.0/24 means IP 192.168.1.10 is allowed; others denied.
  2. Step 2: Understand proxy_cache_purge mycache

    Enables purging cached content for matching requests.
  3. Final Answer:

    The cached content for /purge/page1 is removed -> Option A
  4. Quick Check:

    Allowed IP + PURGE request = cache removed [OK]
Hint: Allowed IP + PURGE request = cache cleared for that URL [OK]
Common Mistakes:
  • Assuming all IPs can purge
  • Thinking PURGE clears entire cache
  • Confusing PURGE with GET request
4. You configured nginx to purge cache with:
location /purge/ {
    deny all;
    proxy_cache_purge mycache;
}

But PURGE requests still return 403 Forbidden. What is the likely cause?
medium
A. Cache is empty so purge fails
B. proxy_cache_purge directive is misspelled
C. Missing allow/deny rules to permit purge requests
D. PURGE method is not supported by nginx

Solution

  1. Step 1: Understand default access control

    Without 'allow', nginx denies all due to 'deny all;' for security.
  2. Step 2: Check purge access rules

    To allow PURGE requests, you must explicitly allow trusted IPs.
  3. Final Answer:

    Missing allow/deny rules to permit purge requests -> Option C
  4. Quick Check:

    deny all without allow = 403 Forbidden on PURGE [OK]
Hint: Always add allow/deny for purge locations [OK]
Common Mistakes:
  • Assuming PURGE method is unsupported
  • Ignoring access control rules
  • Thinking empty cache causes 403
5. You want to purge cached content only for URLs starting with /images/ and restrict purge access to IP 10.0.0.5. Which nginx config snippet correctly achieves this?
hard
A. location /images/ { proxy_cache_purge mycache; allow 10.0.0.5; deny all; }
B. location /purge/images/ { proxy_cache_purge mycache; allow 10.0.0.5; deny all; }
C. location /images/ { proxy_cache mycache; allow 10.0.0.5; deny all; }
D. location /purge/ { proxy_cache_purge mycache; allow all; }

Solution

  1. Step 1: Identify purge location for /images/ URLs

    Purging usually uses a separate location like /purge/images/ to trigger cache removal.
  2. Step 2: Check access control and purge directive

    Allow only IP 10.0.0.5 and deny others with proxy_cache_purge mycache enabled.
  3. Final Answer:

    location /purge/images/ { proxy_cache_purge mycache; allow 10.0.0.5; deny all; } -> Option B
  4. Quick Check:

    Correct purge path + access control = location /purge/images/ { proxy_cache_purge mycache; allow 10.0.0.5; deny all; } [OK]
Hint: Use a purge-specific location with allow/deny for security [OK]
Common Mistakes:
  • Enabling purge in wrong location
  • Using proxy_cache instead of proxy_cache_purge
  • Allowing all IPs to purge
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard