Bird
Raised Fist0
Nginxdevops~20 mins

Nginx vs Apache comparison - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Nginx vs Apache Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Key difference in handling connections

Which statement correctly describes how Nginx and Apache handle client connections?

ABoth Nginx and Apache use process-driven, synchronous architectures.
BBoth Nginx and Apache use event-driven, asynchronous architectures.
CNginx uses an event-driven, asynchronous architecture, while Apache uses a process-driven, synchronous model.
DApache uses an event-driven, asynchronous architecture, while Nginx uses a process-driven, synchronous model.
Attempts:
2 left
💡 Hint

Think about how each server manages multiple requests at the same time.

💻 Command Output
intermediate
2:00remaining
Check active worker processes

What is the output of the following command on a server running Nginx?

ps aux | grep nginx | grep -v grep
AShows only one Nginx process running.
BShows multiple Nginx worker processes and one master process running.
CReturns a syntax error due to incorrect command.
DShows no output because Nginx is not running.
Attempts:
2 left
💡 Hint

Consider how Nginx manages its processes.

Configuration
advanced
3:00remaining
Load balancing configuration in Nginx

Which Nginx configuration snippet correctly sets up a simple round-robin load balancer for two backend servers?

A
upstream backend {
    server backend1.example.com weight=2;
    server backend2.example.com weight=3;
}

server {
    location / {
        proxy_pass http://backend;
    }
}
B
server {
    proxy_pass backend1.example.com backend2.example.com;
}
C
upstream backend {
    server backend1.example.com;
    server backend2.example.com;
    load_balance round_robin;
}

server {
    location / {
        proxy_pass http://backend;
    }
}
D
upstream backend {
    server backend1.example.com;
    server backend2.example.com;
}

server {
    location / {
        proxy_pass http://backend;
    }
}
Attempts:
2 left
💡 Hint

Look for the standard way to define upstream servers and proxy pass.

Troubleshoot
advanced
2:30remaining
Diagnosing 502 Bad Gateway error

You have Nginx configured as a reverse proxy to an application server. When accessing the site, you get a 502 Bad Gateway error. Which is the most likely cause?

AThe backend application server is not running or unreachable.
BNginx configuration file syntax error.
CNginx is running on a different port than the backend server.
DThe client browser cache is corrupted.
Attempts:
2 left
💡 Hint

502 means Nginx cannot get a valid response from the backend.

Best Practice
expert
3:00remaining
Optimizing static content delivery

Which Nginx configuration snippet best improves performance by efficiently serving static files?

A
location /static/ {
    root /var/www/html;
    expires 30d;
    add_header Cache-Control "public";
    try_files $uri =404;
}
B
location /static/ {
    proxy_pass http://backend;
    expires 30d;
}
C
location /static/ {
    root /var/www/html;
    proxy_cache off;
}
D
location /static/ {
    root /var/www/html;
    deny all;
}
Attempts:
2 left
💡 Hint

Think about caching headers and direct file serving.

Practice

(1/5)
1. Which web server is known for using fewer resources and handling many connections efficiently?
easy
A. IIS
B. Apache
C. Nginx
D. Tomcat

Solution

  1. Step 1: Understand resource usage

    Nginx is designed to use less memory and CPU by handling many connections asynchronously.
  2. Step 2: Compare with Apache

    Apache uses more resources because it creates a new process or thread per connection, which is less efficient.
  3. Final Answer:

    Nginx -> Option C
  4. Quick Check:

    Low resource use = Nginx [OK]
Hint: Nginx = efficient, Apache = flexible [OK]
Common Mistakes:
  • Confusing Apache as more efficient
  • Thinking IIS or Tomcat are similar to Nginx
  • Assuming all web servers use same resources
2. Which of the following is the correct way to start the Nginx service on a Linux system using systemd?
easy
A. systemctl start nginx
B. nginx start
C. service nginx start
D. start nginx

Solution

  1. Step 1: Identify systemd command

    Modern Linux systems use systemctl to manage services.
  2. Step 2: Correct syntax for starting Nginx

    The command is systemctl start nginx to start the Nginx service.
  3. Final Answer:

    systemctl start nginx -> Option A
  4. Quick Check:

    Use systemctl for services [OK]
Hint: Use systemctl to manage services on modern Linux [OK]
Common Mistakes:
  • Using old service command on systemd systems
  • Typing nginx start which is invalid
  • Using start nginx which is not a command
3. Given the following Nginx and Apache configurations, which server will handle 10,000 simultaneous connections more efficiently?

# Nginx: event-driven, asynchronous handling
# Apache: process/thread per connection model
medium
A. Nginx will handle better due to asynchronous event-driven model
B. Neither can handle that many connections
C. Both handle equally well
D. Apache will handle better due to process isolation

Solution

  1. Step 1: Understand connection handling models

    Nginx uses an event-driven, asynchronous model that handles many connections with fewer resources.
  2. Step 2: Compare Apache's model

    Apache creates a new process or thread per connection, which uses more memory and CPU, limiting scalability.
  3. Final Answer:

    Nginx will handle better due to asynchronous event-driven model -> Option A
  4. Quick Check:

    Event-driven = better for many connections [OK]
Hint: Event-driven servers handle many connections efficiently [OK]
Common Mistakes:
  • Assuming process isolation means better performance
  • Thinking Apache scales as well as Nginx
  • Ignoring resource limits on Apache
4. You configured Apache to serve static files but notice high CPU usage under load. What is a likely cause compared to Nginx?
medium
A. Apache caches static files inefficiently
B. Apache uses more CPU because it creates a process per request
C. Nginx does not support static files
D. Apache does not support HTTP/1.1

Solution

  1. Step 1: Analyze Apache's process model

    Apache creates a new process or thread for each request, increasing CPU usage under load.
  2. Step 2: Compare with Nginx's approach

    Nginx uses an event-driven model that handles many requests with fewer processes, reducing CPU load.
  3. Final Answer:

    Apache uses more CPU because it creates a process per request -> Option B
  4. Quick Check:

    Process per request = higher CPU [OK]
Hint: Process per request = more CPU usage [OK]
Common Mistakes:
  • Thinking Apache caches static files poorly
  • Believing Nginx lacks static file support
  • Incorrectly assuming Apache lacks HTTP/1.1 support
5. You want to serve a high-traffic website with many simultaneous users and low memory usage. Which setup is best and why?
hard
A. Use Nginx only as a reverse proxy, Apache for static files
B. Use Apache with many worker processes for flexibility
C. Use Apache with default prefork module for stability
D. Use Nginx for event-driven handling and low memory use

Solution

  1. Step 1: Identify requirements

    High traffic and low memory use require efficient connection handling and low resource consumption.
  2. Step 2: Evaluate server models

    Nginx uses an event-driven model that handles many connections with low memory, ideal for high traffic.
  3. Step 3: Compare other options

    Apache with many workers uses more memory; prefork is stable but heavy; using Nginx only as proxy adds complexity.
  4. Final Answer:

    Use Nginx for event-driven handling and low memory use -> Option D
  5. Quick Check:

    Event-driven + low memory = Nginx best [OK]
Hint: For high traffic and low memory, choose Nginx [OK]
Common Mistakes:
  • Choosing Apache for low memory use
  • Ignoring Nginx's event-driven advantage
  • Overcomplicating with mixed setups