B. The response includes header X-Test: Hello with 404 status
C. The response returns 200 OK with X-Test header
D. The response returns 404 without X-Test header
Solution
Step 1: Understand default add_header behavior on errors
By default, add_header does NOT add headers on error responses like 404.
Step 2: Analyze the config and request
The location returns 404, so X-Test header is omitted unless always is used.
Final Answer:
The response returns 404 without X-Test header -> Option D
Quick Check:
Headers not added on errors without always [OK]
Hint: Headers need 'always' to appear on error responses [OK]
Common Mistakes:
Assuming headers always appear on error responses
Confusing return status with header presence
Expecting 200 OK instead of 404
4. You want to add a security header X-Frame-Options: DENY to all responses including errors. Which nginx config fixes this incorrect snippet?
add_header X-Frame-Options DENY;
But headers are missing on 404 pages.
medium
A. Change to add_header X-Frame-Options DENY always;
B. Add always; on a separate line
C. Use add_header X-Frame-Options DENY on_error;
D. Move add_header inside error_page block
Solution
Step 1: Identify why headers are missing on errors
By default, add_header skips error responses unless always is added.
Step 2: Fix syntax to include headers on all responses
Adding always on the same line ensures headers appear even on errors.
Final Answer:
Change to add_header X-Frame-Options DENY always; -> Option A
Quick Check:
Use 'always' on same line to add headers on errors [OK]
Hint: Add 'always' on same line to include headers on errors [OK]
Common Mistakes:
Placing 'always' on a separate line
Using invalid keywords like 'on_error'
Moving add_header inside unrelated blocks
5. You want to add two headers: Cache-Control: no-store for all responses, and Strict-Transport-Security: max-age=31536000 only for successful responses (status 200-299). Which nginx config achieves this correctly?
hard
A. add_header Cache-Control no-store always;
add_header Strict-Transport-Security max-age=31536000;
B. add_header Cache-Control no-store;
add_header Strict-Transport-Security max-age=31536000 always;
C. add_header Cache-Control no-store;
add_header Strict-Transport-Security max-age=31536000;
D. add_header Cache-Control no-store always;
add_header Strict-Transport-Security max-age=31536000 always;
Solution
Step 1: Understand 'always' effect on headers
The always flag makes headers appear on all responses including errors.
Step 2: Apply 'always' only to Cache-Control
We want Cache-Control on all responses, so add always there. For Strict-Transport-Security, omit always to restrict to 2xx responses.
Final Answer:
add_header Cache-Control no-store always;
add_header Strict-Transport-Security max-age=31536000; -> Option A
Quick Check:
'always' for all responses, omit for success-only [OK]
Hint: Use 'always' only for headers needed on errors [OK]
Common Mistakes:
Adding 'always' to all headers causing unwanted error headers
Omitting 'always' for headers needed on errors
Misunderstanding which responses get headers without 'always'