What is HTTP/2 and why is it important in web servers like nginx?
HTTP/2 is a newer version of the HTTP protocol that makes websites load faster by allowing multiple requests at the same time over one connection. It improves speed and efficiency compared to HTTP/1.1.
Click to reveal answer
beginner
How do you enable HTTP/2 in an nginx server block?
Add the keyword http2 to the listen directive in your server block, for example: listen 443 ssl http2;
Click to reveal answer
intermediate
Why must SSL/TLS be enabled to use HTTP/2 in nginx?
Most browsers require HTTP/2 to run over a secure connection (HTTPS). So nginx must have SSL/TLS configured to use HTTP/2.
Click to reveal answer
intermediate
What is the purpose of the ssl_certificate and ssl_certificate_key directives in nginx HTTP/2 configuration?
They specify the paths to your SSL certificate and private key files. These files enable encrypted connections needed for HTTP/2.
Click to reveal answer
beginner
How can you verify that HTTP/2 is working on your nginx server?
Use browser developer tools or online tools to check the protocol used. You can also run curl -I --http2 https://yourdomain.com to see if HTTP/2 is active.
Click to reveal answer
Which directive enables HTTP/2 in an nginx server block?
Ahttp2_enable on;
Benable_http2 true;
Clisten 443 ssl http2;
Dprotocol http2;
✗ Incorrect
The correct way to enable HTTP/2 is by adding 'http2' to the listen directive, like 'listen 443 ssl http2;'.
Why is SSL/TLS required for HTTP/2 in nginx?
ABecause browsers require HTTP/2 over secure connections
BBecause HTTP/2 only works on port 80
CBecause nginx does not support HTTP/2 without SSL
DBecause SSL/TLS speeds up HTTP/2
✗ Incorrect
Browsers require HTTP/2 to be used over HTTPS, so SSL/TLS must be enabled.
Which command can you use to check if your nginx server supports HTTP/2?
Anginx -t --http2
Bcurl -I --http2 https://yourdomain.com
Ccurl --http1.1 https://yourdomain.com
Dnginx -v http2
✗ Incorrect
The curl command with --http2 option checks if the server supports HTTP/2.
What files must be specified to enable SSL for HTTP/2 in nginx?
Assl_key and ssl_cert
Bhttp2_certificate and http2_key
Ctls_certificate and tls_key
Dssl_certificate and ssl_certificate_key
✗ Incorrect
The directives ssl_certificate and ssl_certificate_key specify the SSL certificate and key files.
What is a main benefit of HTTP/2 over HTTP/1.1?
AAllows multiple requests over one connection
BUses less secure connections
CRequires more server memory
DOnly works with IPv6
✗ Incorrect
HTTP/2 allows multiplexing multiple requests on a single connection, improving speed.
Explain how to configure HTTP/2 in nginx including SSL setup.
Think about the server block and secure connection requirements.
You got /4 concepts.
Describe how you can verify that HTTP/2 is active on your nginx server.
Use simple command line tools or browser features.
You got /3 concepts.
Practice
(1/5)
1. What is the correct way to enable HTTP/2 in an nginx server block?
easy
A. Add http2 to the location block
B. Add http2 to the server_name directive
C. Add http2 to the listen directive with SSL enabled
D. Add http2 to the root directive
Solution
Step 1: Understand HTTP/2 enabling in nginx
HTTP/2 is enabled by adding the http2 parameter to the listen directive, which must be used with SSL (HTTPS).
Step 2: Identify correct directive usage
The http2 parameter does not belong in server_name, root, or location blocks.
Final Answer:
Add http2 to the listen directive with SSL enabled -> Option C
Quick Check:
Enable HTTP/2 by adding http2 to listen with SSL [OK]
Hint: Add 'http2' only in listen directive with SSL [OK]
Common Mistakes:
Adding http2 to server_name or root directives
Forgetting to enable SSL when using http2
Placing http2 inside location blocks
2. Which of the following is the correct syntax to enable HTTP/2 on port 443 in nginx?
easy
A. listen 443 ssl;
B. listen http2 443 ssl;
C. listen 443 http2;
D. listen 443 ssl http2;
Solution
Step 1: Review nginx listen directive syntax
The correct order is listen [port] ssl http2; to enable SSL and HTTP/2 on the port.
Step 2: Check each option
listen 443 ssl http2; uses correct syntax: listen 443 ssl http2;. listen http2 443 ssl; reverses order but is invalid. listen 443 ssl; misses http2. listen 443 http2; misses ssl, which is required for http2.
Final Answer:
listen 443 ssl http2; -> Option D
Quick Check:
Correct syntax is 'listen 443 ssl http2;' [OK]
Hint: Use 'listen 443 ssl http2;' exactly for HTTP/2 [OK]
Common Mistakes:
Omitting ssl when enabling http2
Placing http2 before ssl in listen directive
Using http2 without SSL on port 443
3. Given this nginx server block snippet, what will happen when a client connects?
A. The server will accept HTTPS connections using HTTP/2 protocol
B. The server will accept HTTP connections only, no HTTP/2
C. The server will reject connections due to missing http2 directive
D. The server will accept HTTPS but use HTTP/1.1 only
Solution
Step 1: Analyze listen directive
The listen directive includes ssl and http2, enabling HTTPS with HTTP/2 support.
Step 2: Confirm SSL certificates presence
SSL certificate and key files are specified, so HTTPS can work properly.
Final Answer:
The server will accept HTTPS connections using HTTP/2 protocol -> Option A
Quick Check:
listen with ssl and http2 means HTTPS + HTTP/2 enabled [OK]
Hint: ssl + http2 in listen means HTTPS with HTTP/2 [OK]
Common Mistakes:
Assuming HTTP/2 works without ssl
Confusing HTTP and HTTPS ports
Ignoring the http2 parameter in listen
4. You added http2 to your nginx listen directive but HTTP/2 is not working. Which configuration mistake could cause this?
medium
A. Forgetting to enable SSL (missing ssl in listen directive)
B. Using http2 in the server_name directive
C. Setting listen to port 80 with http2
D. Adding http2 inside the location block
Solution
Step 1: Understand HTTP/2 requirements in nginx
HTTP/2 requires SSL (HTTPS) to be enabled in nginx; without ssl in the listen directive, HTTP/2 won't work.
Step 2: Evaluate other options
Options A, C, and D are invalid uses of http2 but the main cause is missing SSL.
Final Answer:
Forgetting to enable SSL (missing ssl in listen directive) -> Option A
Quick Check:
HTTP/2 needs SSL enabled in listen directive [OK]
Hint: Always include ssl with http2 in listen directive [OK]
Common Mistakes:
Not enabling ssl with http2
Placing http2 in wrong directives
Trying http2 on port 80 without ssl
5. You want to configure nginx to serve HTTP/2 on port 443 and redirect all HTTP (port 80) traffic to HTTPS. Which configuration snippet correctly achieves this?
hard
A.
server {
listen 80 http2;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
}