Bird
Raised Fist0
Nginxdevops~20 mins

Open file cache in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Open File Cache Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the purpose of the open_file_cache directive in nginx?

nginx uses the open_file_cache directive to improve performance. What does it specifically cache?

AIt caches DNS lookups to speed up domain name resolution.
BIt caches the entire content of files in memory for faster delivery.
CIt caches open file descriptors to reduce file open/close operations.
DIt caches HTTP headers to reduce processing time.
Attempts:
2 left
💡 Hint

Think about what happens when nginx serves static files repeatedly.

❓ Configuration
intermediate
2:00remaining
Which configuration snippet correctly enables open_file_cache with 100 max cached files and 60 seconds inactive timeout?

Choose the correct nginx configuration to enable open_file_cache with a maximum of 100 cached files and an inactive timeout of 60 seconds.

Aopen_file_cache max_files=100 inactive_timeout=60;
Bopen_file_cache 100 60s;
Copen_file_cache max=60 inactive=100s;
Dopen_file_cache max=100 inactive=60s;
Attempts:
2 left
💡 Hint

Check the correct parameter names and syntax for open_file_cache.

💻 Command Output
advanced
2:00remaining
What error will nginx report if open_file_cache is set with an invalid time unit?

Given this configuration snippet:

open_file_cache max=50 inactive=5x;

What error message will nginx show when testing this config?

Anginx: [emerg] invalid time value "5x" in /etc/nginx/nginx.conf:10
Bnginx: [warn] unknown directive "open_file_cache" in /etc/nginx/nginx.conf:10
Cnginx: [error] failed to start due to syntax error in open_file_cache
Dnginx: configuration file /etc/nginx/nginx.conf test is successful
Attempts:
2 left
💡 Hint

Look for errors related to invalid time formats in nginx.

❓ Troubleshoot
advanced
2:00remaining
Why might enabling open_file_cache not improve performance as expected?

You enabled open_file_cache with proper settings, but nginx performance did not improve. Which reason is most likely?

AThe <code>open_file_cache_valid</code> directive is set too low, causing frequent cache invalidation.
BThe server has too much free memory, so caching is disabled automatically.
CThe <code>open_file_cache</code> directive only works for dynamic content, not static files.
DThe <code>open_file_cache_min_uses</code> is set to 0, so files are never cached.
Attempts:
2 left
💡 Hint

Think about how cache validity affects caching benefits.

✅ Best Practice
expert
2:00remaining
What is the recommended way to configure open_file_cache for a high-traffic static file server?

For a high-traffic nginx server serving mostly static files, which configuration is best practice for open_file_cache?

Aopen_file_cache max=100 inactive=30s; open_file_cache_valid 5s; open_file_cache_min_uses 1;
Bopen_file_cache max=10000 inactive=120s; open_file_cache_valid 60s; open_file_cache_min_uses 2;
Copen_file_cache max=500 inactive=10s; open_file_cache_valid 1s; open_file_cache_min_uses 0;
Dopen_file_cache max=50 inactive=300s; open_file_cache_valid 300s; open_file_cache_min_uses 10;
Attempts:
2 left
💡 Hint

Consider cache size, validity, and minimum uses for effective caching.

Practice

(1/5)
1. What is the main purpose of the open_file_cache directive in nginx?
easy
A. To limit the number of open connections to clients
B. To store file information in memory to speed up file access
C. To cache HTTP responses from upstream servers
D. To compress files before sending them to clients

Solution

  1. Step 1: Understand the role of open_file_cache

    The open_file_cache directive caches file metadata like file descriptors and attributes.
  2. Step 2: Identify its effect on performance

    By caching file info, nginx reduces disk access and speeds up serving static files.
  3. Final Answer:

    To store file information in memory to speed up file access -> Option B
  4. Quick Check:

    open_file_cache purpose = cache file info [OK]
Hint: Remember: open_file_cache speeds file access by caching file info [OK]
Common Mistakes:
  • Confusing open_file_cache with HTTP response caching
  • Thinking it limits client connections
  • Assuming it compresses files
2. Which of the following is the correct syntax to enable open file cache with 1000 max cached files and 60 seconds inactive timeout?
easy
A. open_file_cache max=1000 inactive=60;
B. open_file_cache 1000 60s;
C. open_file_cache max=1000 inactive=60s;
D. open_file_cache max=1000 inactive=60sec;

Solution

  1. Step 1: Recall correct open_file_cache syntax

    The syntax requires named parameters like max= and inactive= with time units.
  2. Step 2: Check each option for correctness

    open_file_cache max=1000 inactive=60s; uses correct parameter names and time unit s for seconds.
  3. Final Answer:

    open_file_cache max=1000 inactive=60s; -> Option C
  4. Quick Check:

    Use named params with units for open_file_cache [OK]
Hint: Use named parameters with units like 'inactive=60s' [OK]
Common Mistakes:
  • Omitting parameter names
  • Missing time units for inactive
  • Using incorrect time unit abbreviations
3. Given this nginx config snippet:
open_file_cache max=2 inactive=30s;
open_file_cache_valid 10s;

What happens when nginx tries to serve 3 different files within 10 seconds?
medium
A. All 3 files are cached because open_file_cache_valid is 10s
B. All files are cached but expire after 30 seconds
C. No files are cached because max is less than 3
D. Only 2 files are cached; the third file info is not cached

Solution

  1. Step 1: Understand max parameter effect

    The max=2 limits cache to 2 file entries only.
  2. Step 2: Analyze caching of 3 files

    When 3 files are requested, only 2 can be cached; the third is not cached.
  3. Final Answer:

    Only 2 files are cached; the third file info is not cached -> Option D
  4. Quick Check:

    max=2 limits cache size to 2 files [OK]
Hint: max limits cached files count; extras are not cached [OK]
Common Mistakes:
  • Assuming all files cache regardless of max
  • Confusing open_file_cache_valid with max
  • Thinking inactive controls cache size
4. You configured open_file_cache max=100 inactive=60s; but notice no caching effect. What is a likely cause?
medium
A. You forgot to enable open_file_cache_valid directive
B. The max value is too high to cache files
C. The inactive time is too short to cache files
D. open_file_cache only works with dynamic content

Solution

  1. Step 1: Check required directives for caching

    Besides open_file_cache, open_file_cache_valid must be set to define cache validity.
  2. Step 2: Identify missing directive effect

    Without open_file_cache_valid, cached entries expire immediately, so no caching effect.
  3. Final Answer:

    You forgot to enable open_file_cache_valid directive -> Option A
  4. Quick Check:

    open_file_cache_valid enables cache duration [OK]
Hint: Always set open_file_cache_valid to activate caching [OK]
Common Mistakes:
  • Ignoring open_file_cache_valid directive
  • Misunderstanding max and inactive roles
  • Thinking open_file_cache works only for dynamic content
5. You want to optimize nginx for a high-traffic static site. Which open_file_cache settings best improve performance while avoiding stale data?
hard
A. open_file_cache max=1000 inactive=60s; open_file_cache_valid 30s;
B. open_file_cache max=10 inactive=300s; open_file_cache_valid 300s;
C. open_file_cache max=5000 inactive=5s; open_file_cache_valid 1s;
D. open_file_cache max=100 inactive=3600s; open_file_cache_valid 3600s;

Solution

  1. Step 1: Balance cache size and freshness

    High-traffic static sites benefit from a large cache (max=1000) and moderate inactive timeout (60s) to keep data fresh.
  2. Step 2: Set cache validity to avoid stale data

    open_file_cache_valid 30s ensures cached info refreshes often enough to prevent stale data.
  3. Final Answer:

    open_file_cache max=1000 inactive=60s; open_file_cache_valid 30s; -> Option A
  4. Quick Check:

    Large max + moderate inactive + short valid = best performance [OK]
Hint: Use large max, moderate inactive, short valid for fresh cache [OK]
Common Mistakes:
  • Setting max too low for traffic
  • Using too long inactive or valid causing stale cache
  • Setting valid too short causing overhead
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