0
0
Nginxdevops~30 mins

Nginx vs Apache comparison - Hands-On Comparison

Choose your learning style9 modes available
Nginx vs Apache Comparison
📖 Scenario: You are setting up a web server for a small business website. You want to compare two popular web servers, Nginx and Apache, to understand their basic configuration differences and how they serve web pages.
🎯 Goal: Build simple configuration files for both Nginx and Apache to serve a static HTML page. Learn how to set up the server root, listen on port 80, and serve an index.html file.
📋 What You'll Learn
Create a basic Nginx configuration file to serve static content
Create a basic Apache configuration file to serve static content
Understand the key differences in configuration syntax
Test that both servers serve the index.html page correctly
💡 Why This Matters
🌍 Real World
Web servers like Nginx and Apache are used worldwide to host websites and web applications. Knowing how to configure them is essential for deploying and managing web services.
💼 Career
Many DevOps and system administrator roles require knowledge of web server configuration and management. Understanding Nginx and Apache basics is a key skill for these jobs.
Progress0 / 4 steps
1
Create Nginx configuration file
Create a file named nginx.conf with a server block that listens on port 80, sets the root directory to /var/www/html, and serves index.html as the default file.
Nginx
Need a hint?

Use the server block to define the listening port and root directory. The location / block handles requests to the root URL.

2
Create Apache configuration file
Create a file named apache.conf with a <VirtualHost *:80> block that sets the DocumentRoot to /var/www/html and specifies index.html as the default directory index.
Nginx
Need a hint?

Use the <VirtualHost *:80> block to define the listening port and document root. The DirectoryIndex directive sets the default file.

3
Compare configuration differences
Add comments in both nginx.conf and apache.conf files explaining the key differences: Nginx uses server blocks and directives like listen, root, and location, while Apache uses <VirtualHost> blocks and directives like DocumentRoot and DirectoryIndex.
Nginx
Need a hint?

Write simple comments starting with # describing the main configuration style differences.

4
Test serving index.html page
Write two commands: one to start Nginx using nginx.conf and one to start Apache using apache.conf. Then write a command to fetch the homepage from localhost using curl. Print the output of the curl command.
Nginx
Need a hint?

Use sudo nginx -c nginx.conf to start Nginx with your config, sudo apachectl -f apache.conf to start Apache, and curl http://localhost to fetch the homepage.