Bird
Raised Fist0
Nginxdevops~10 mins

OCSP stapling in Nginx - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - OCSP stapling
Client connects to server
↓
Server sends certificate
↓
Server attaches OCSP response (staple)
↓
Client verifies certificate + OCSP response
↓
Connection established if valid
OCSP stapling lets the server send certificate status to the client, speeding up verification.
Execution Sample
Nginx
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;

server {
  listen 443 ssl;
  ssl_certificate /etc/ssl/certs/server.crt;
  ssl_certificate_key /etc/ssl/private/server.key;
}
This config enables OCSP stapling in nginx with DNS resolvers for OCSP queries.
Process Table
StepActionServer StateClient ActionResult
1Client connects to server on HTTPSWaiting for connectionSends ClientHelloConnection starts
2Server sends certificateSends server.crtReceives certificateClient prepares to verify
3Server attaches OCSP stapleFetches OCSP response from CAReceives OCSP response with certificateClient skips separate OCSP query
4Client verifies certificate and OCSP responseOCSP response validChecks certificate statusVerification successful
5Connection establishedSecure connection openUses connectionData exchanged securely
6OCSP response expiresServer fetches new OCSP responseNext client connection gets fresh stapleStapling continues
💡 OCSP stapling improves speed by avoiding client OCSP queries; server refreshes staple periodically.
Status Tracker
VariableStartAfter Step 3After Step 6
OCSP ResponseNoneFetched and attachedRefreshed and attached
Client VerificationPendingVerified with stapleVerified with fresh staple
Key Moments - 3 Insights
Why does the client not need to query the OCSP server directly?
Because the server sends the OCSP response (staple) during the TLS handshake as shown in step 3 of the execution_table.
What happens if the OCSP response expires?
The server fetches a new OCSP response before the next client connection, as shown in step 6, ensuring fresh status.
Why do we configure DNS resolvers in nginx for OCSP stapling?
Because nginx needs to query the OCSP server's URL, which requires DNS resolution, as configured by the resolver directive in the sample code.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the server attach the OCSP response to the certificate?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Check the 'Action' column for when the server attaches the OCSP staple.
According to variable_tracker, what is the state of 'OCSP Response' after step 6?
ANone
BFetched and attached
CRefreshed and attached
DExpired
💡 Hint
Look at the 'After Step 6' column for 'OCSP Response' in variable_tracker.
If the server did not refresh the OCSP response, what would happen at step 6?
AClient would receive a fresh OCSP response
BClient would query OCSP server directly
CConnection would fail immediately
DServer would send no certificate
💡 Hint
Refer to key_moments about what happens when OCSP response expires.
Concept Snapshot
OCSP stapling lets the server send certificate status during TLS handshake.
Enable with 'ssl_stapling on;' and 'ssl_stapling_verify on;' in nginx.
Configure DNS resolvers for OCSP queries.
Improves speed by avoiding client OCSP lookups.
Server refreshes OCSP response periodically.
Full Transcript
OCSP stapling is a way for the server to send proof that its certificate is still valid during the TLS handshake. This saves the client from asking the certificate authority directly, making connections faster. In nginx, you enable it with 'ssl_stapling on;' and 'ssl_stapling_verify on;'. You also set DNS resolvers so nginx can find the OCSP server. When a client connects, the server sends its certificate plus the OCSP response. The client checks both and if valid, the secure connection proceeds. The server refreshes the OCSP response regularly to keep it fresh. This process improves security and speed for HTTPS connections.

Practice

(1/5)
1. What is the main purpose of enabling OCSP stapling in nginx?
easy
A. To encrypt the website traffic with a stronger cipher
B. To block unauthorized IP addresses automatically
C. To speed up HTTPS by caching the certificate status
D. To compress website content for faster loading

Solution

  1. Step 1: Understand OCSP stapling concept

    OCSP stapling allows the server to cache the certificate status from the certificate authority, reducing the need for clients to query it directly.
  2. Step 2: Identify the main benefit in nginx

    This caching speeds up HTTPS connections by reducing latency and improving performance.
  3. Final Answer:

    To speed up HTTPS by caching the certificate status -> Option C
  4. Quick Check:

    OCSP stapling = speed up HTTPS [OK]
Hint: OCSP stapling caches cert status to speed HTTPS [OK]
Common Mistakes:
  • Confusing OCSP stapling with encryption methods
  • Thinking it blocks IP addresses
  • Assuming it compresses website content
2. Which of the following is the correct nginx directive to enable OCSP stapling?
easy
A. ssl_ocsp on;
B. ssl_stapling_enable true;
C. ssl_ocsp_stapling enable;
D. ssl_stapling on;

Solution

  1. Step 1: Recall nginx directive syntax for OCSP stapling

    The correct directive to enable OCSP stapling in nginx is ssl_stapling on;.
  2. Step 2: Check each option for syntax correctness

    Options A, B, and C use incorrect directive names or syntax.
  3. Final Answer:

    ssl_stapling on; -> Option D
  4. Quick Check:

    Enable OCSP stapling with ssl_stapling on; [OK]
Hint: Use ssl_stapling on; to enable OCSP stapling [OK]
Common Mistakes:
  • Using incorrect directive names like ssl_ocsp
  • Adding extra words like _enable or enable
  • Using true/false instead of on/off
3. Given this nginx snippet, what will happen if ssl_stapling is enabled but resolver is not set?
server {
  listen 443 ssl;
  ssl_certificate /etc/ssl/cert.pem;
  ssl_certificate_key /etc/ssl/key.pem;
  ssl_stapling on;
}
medium
A. nginx will log errors but continue running without stapling
B. nginx will fail to start due to missing resolver
C. OCSP stapling will be disabled silently
D. OCSP stapling will work normally without issues

Solution

  1. Step 1: Understand resolver role in OCSP stapling

    nginx needs a DNS resolver configured to fetch OCSP responses from the certificate authority.
  2. Step 2: Analyze behavior without resolver

    If no resolver is set, nginx cannot fetch OCSP responses, so it logs errors but continues running without stapling.
  3. Final Answer:

    nginx will log errors but continue running without stapling -> Option A
  4. Quick Check:

    Missing resolver = errors logged, no stapling [OK]
Hint: Missing resolver logs errors, disables stapling silently [OK]
Common Mistakes:
  • Assuming nginx fails to start
  • Thinking stapling works without resolver
  • Believing stapling disables silently without logs
4. You enabled ssl_stapling on; and set a resolver, but nginx still does not staple OCSP responses. What is the most likely cause?
medium
A. The SSL certificate does not include the OCSP responder URL
B. The ssl_certificate_key file is missing
C. The server is listening on port 80 instead of 443
D. The ssl_protocols directive is missing

Solution

  1. Step 1: Check prerequisites for OCSP stapling

    OCSP stapling requires the SSL certificate to include an OCSP responder URL to fetch status.
  2. Step 2: Identify why stapling fails despite correct config

    If the certificate lacks the OCSP responder URL, nginx cannot get the status, so stapling fails.
  3. Final Answer:

    The SSL certificate does not include the OCSP responder URL -> Option A
  4. Quick Check:

    Missing OCSP URL in cert = stapling fails [OK]
Hint: Cert must have OCSP URL for stapling to work [OK]
Common Mistakes:
  • Thinking missing key file causes stapling failure
  • Confusing HTTP port with SSL port
  • Assuming ssl_protocols affects stapling directly
5. You want to enable OCSP stapling in nginx with these requirements: - Use Google's public DNS resolver - Enable stapling - Ensure nginx reloads config safely Which configuration snippet correctly achieves this?
server {
  listen 443 ssl;
  ssl_certificate /etc/ssl/cert.pem;
  ssl_certificate_key /etc/ssl/key.pem;
  # Your config here
}
hard
A. resolver 8.8.8.8; ssl_stapling off; ssl_stapling_verify on;
B. resolver 8.8.8.8 8.8.4.4 valid=300s; ssl_stapling on; ssl_stapling_verify on;
C. ssl_stapling on; ssl_stapling_verify off; resolver 1.1.1.1;
D. resolver 8.8.8.8 8.8.4.4; ssl_stapling on; ssl_stapling_verify off;

Solution

  1. Step 1: Set resolver with Google's DNS and validity

    Use resolver 8.8.8.8 8.8.4.4 valid=300s; to specify DNS servers and cache time.
  2. Step 2: Enable OCSP stapling and verification

    Set ssl_stapling on; and ssl_stapling_verify on; to enable stapling and verify OCSP responses.
  3. Step 3: Confirm safe reload

    After config changes, run nginx -t to test and nginx -s reload to reload safely.
  4. Final Answer:

    resolver 8.8.8.8 8.8.4.4 valid=300s; ssl_stapling on; ssl_stapling_verify on; -> Option B
  5. Quick Check:

    Correct resolver + stapling on + verify on = resolver 8.8.8.8 8.8.4.4 valid=300s; ssl_stapling on; ssl_stapling_verify on; [OK]
Hint: Use resolver with valid=, enable stapling and verify on [OK]
Common Mistakes:
  • Forgetting ssl_stapling_verify on
  • Using only one resolver without valid time
  • Disabling stapling or verification accidentally
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