📖 Scenario: You are setting up a simple web server using nginx to understand how HTTPS protects data when people visit your website. Imagine you run a small online store and want to keep your customers' information safe.
🎯 Goal: Learn how to configure nginx to use HTTPS with SSL certificates and see how it encrypts communication between the server and the browser.
📋 What You'll Learn
Create a basic nginx server block configuration for HTTP
Add SSL certificate and key file paths as configuration variables
Modify the server block to enable HTTPS using SSL
Display the final nginx configuration showing HTTPS setup
💡 Why This Matters
🌍 Real World
Websites use HTTPS to protect user data like passwords and credit card numbers from being stolen during transmission.
💼 Career
Understanding HTTPS setup is essential for DevOps roles managing web servers and ensuring secure communication.
Progress0 / 4 steps
1
Create a basic HTTP server block
Write an nginx server block configuration named server that listens on port 80 and serves files from /var/www/html. Use server_name example.com; inside the block.
Nginx
Hint
Think of this as telling nginx to listen for normal web traffic on port 80 and serve your website files.
2
Add SSL certificate and key file paths
Add two variables named ssl_certificate and ssl_certificate_key with values /etc/ssl/certs/example.crt and /etc/ssl/private/example.key respectively. Place them outside the server block as simple variable assignments.
Nginx
Hint
These paths tell nginx where to find your SSL certificate and private key files.
3
Enable HTTPS in the server block
Modify the existing server block to listen on port 443 ssl instead of 80. Inside the block, add the lines ssl_certificate /etc/ssl/certs/example.crt; and ssl_certificate_key /etc/ssl/private/example.key; to enable SSL.
Nginx
Hint
Listening on port 443 with SSL enabled tells nginx to use HTTPS for secure communication.
4
Display the final HTTPS server block configuration
Print the entire server block configuration that listens on port 443 ssl and includes the SSL certificate and key lines exactly as shown.
Nginx
Hint
Showing the final configuration helps confirm HTTPS is set up correctly.
Practice
(1/5)
1. Why does HTTPS secure communication between a browser and a website?
easy
A. It changes the website's design automatically.
B. It makes the website load faster.
C. It encrypts data so others cannot read it during transfer.
D. It blocks all internet traffic except from trusted sites.
Solution
Step 1: Understand HTTPS function
HTTPS encrypts data sent between browser and website to protect privacy.
Step 2: Identify the security benefit
Encryption prevents attackers from reading or changing the data during transfer.
Final Answer:
It encrypts data so others cannot read it during transfer. -> Option C
Quick Check:
Encryption = Secure communication [OK]
Hint: HTTPS means encrypted data transfer [OK]
Common Mistakes:
Thinking HTTPS speeds up the website
Believing HTTPS changes website design
Assuming HTTPS blocks all traffic except trusted
2. Which nginx configuration line enables HTTPS on port 443?
easy
A. listen 443 ssl;
B. listen 80 ssl;
C. listen 443 http;
D. listen 80 http;
Solution
Step 1: Identify HTTPS port and protocol
HTTPS uses port 443 and requires SSL enabled in nginx.
Step 2: Match correct listen directive
Only "listen 443 ssl;" correctly enables SSL on port 443.
Final Answer:
listen 443 ssl; -> Option A
Quick Check:
Port 443 + ssl = HTTPS enabled [OK]
Hint: HTTPS always uses port 443 with ssl flag [OK]
Common Mistakes:
Using port 80 for HTTPS
Missing ssl keyword
Confusing http and https protocols
3. Given this nginx snippet, what happens when a user visits https://example.com?