Bird
Raised Fist0
Nginxdevops~20 mins

First Nginx configuration - Practice Problems & Coding Challenges

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 Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of the command to test Nginx configuration?
You have created a new Nginx configuration file. Which command will correctly test the syntax of this configuration and what will be the output if the syntax is correct?
Nginx
sudo nginx -t
A
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
BSyntax error in /etc/nginx/nginx.conf at line 10
Cnginx: command not found
DFailed to start nginx.service: Unit nginx.service not found.
Attempts:
2 left
💡 Hint
Use the command that checks Nginx configuration syntax without starting the server.
Configuration
intermediate
2:00remaining
Identify the correct server block to serve a static website on port 8080
You want Nginx to serve a static website from /var/www/html on port 8080. Which server block configuration is correct?
Aserver { listen 8080; root /var/www; index index.html; }
Bserver { listen 8080; root /var/www/html; index index.html; }
Cserver { listen 80; root /var/www/html; index index.html; }
Dserver { listen 8080; root /var/www/html; }
Attempts:
2 left
💡 Hint
The server block must listen on port 8080 and point root to the exact folder with index.html.
Troubleshoot
advanced
2:00remaining
Why does Nginx fail to start after adding a new server block?
You added this server block to your Nginx config but Nginx fails to start: server { listen 80; server_name example.com; root /var/www/example; index index.html; location / { try_files $uri $uri/ =404 } } What is the cause of the failure?
Nginx
server {
  listen 80;
  server_name example.com;
  root /var/www/example;
  index index.html;
  location / {
    try_files $uri $uri/ =404
  }
}
Aserver_name directive is invalid
BRoot directory /var/www/example does not exist
CMissing semicolon after 'try_files $uri $uri/ =404' causes syntax error
Dlisten directive must specify IP address
Attempts:
2 left
💡 Hint
Check the syntax carefully for missing punctuation.
🔀 Workflow
advanced
2:00remaining
Order the steps to safely reload Nginx after configuration changes
Put these steps in the correct order to safely apply new Nginx configuration changes without downtime.
A3,1,2,4
B1,3,2,4
C3,2,1,4
D2,3,1,4
Attempts:
2 left
💡 Hint
You must edit first, then test, then reload, then check status.
Best Practice
expert
2:00remaining
Which practice improves Nginx configuration maintainability?
You want to keep your Nginx configuration easy to manage as it grows. Which practice is best?
ADisable syntax testing to speed up reloads
BPut all server blocks in one large nginx.conf file
CAvoid comments to keep files clean
DUse include directives to split configuration into smaller files
Attempts:
2 left
💡 Hint
Think about how to organize files for clarity and ease of updates.

Practice

(1/5)
1. What is the purpose of the server block in an Nginx configuration?
easy
A. To start the Nginx service
B. To define settings for a specific website or domain
C. To specify the operating system
D. To install Nginx modules

Solution

  1. Step 1: Understand Nginx configuration structure

    Nginx uses server blocks to group settings for each website or domain it serves.
  2. Step 2: Identify the role of server block

    The server block tells Nginx how to handle requests for a particular site, including ports and root folder.
  3. Final Answer:

    To define settings for a specific website or domain -> Option B
  4. Quick Check:

    server block = website settings [OK]
Hint: Remember: server block = one website config [OK]
Common Mistakes:
  • Confusing server block with service start command
  • Thinking server block installs software
  • Mixing server block with OS settings
2. Which of the following is the correct syntax to listen on port 80 in an Nginx server block?
easy
A. listen: 80
B. listen = 80;
C. listen 80;
D. port 80;

Solution

  1. Step 1: Recall Nginx directive syntax

    Nginx directives end with a semicolon and use space-separated key and value.
  2. Step 2: Check the correct listen syntax

    The correct way to specify port 80 is listen 80; without equals or colon.
  3. Final Answer:

    listen 80; -> Option C
  4. Quick Check:

    listen 80; = correct syntax [OK]
Hint: Nginx directives end with semicolon, no equals sign [OK]
Common Mistakes:
  • Using equals sign (=) in directives
  • Using colon (:) instead of space
  • Omitting semicolon at end
3. Given this Nginx configuration snippet, what is the root folder for the website?
server {
    listen 80;
    root /var/www/html;
    index index.html;
}
medium
A. /home/user
B. /etc/nginx
C. /usr/share/nginx
D. /var/www/html

Solution

  1. Step 1: Locate the root directive

    The root directive sets the folder where website files are served from.
  2. Step 2: Read the root path value

    Here, root /var/www/html; means the website files are in /var/www/html.
  3. Final Answer:

    /var/www/html -> Option D
  4. Quick Check:

    root folder = /var/www/html [OK]
Hint: Look for root directive to find website folder [OK]
Common Mistakes:
  • Confusing root with index directive
  • Assuming default folder without checking config
  • Mixing root with Nginx installation folders
4. Identify the error in this Nginx configuration snippet:
server {
    listen 80
    root /var/www/html;
    index index.html;
}
medium
A. Missing semicolon after listen 80
B. Wrong root path
C. index directive should be index.htm
D. listen directive should be inside location block

Solution

  1. Step 1: Check syntax of each directive

    Each directive must end with a semicolon in Nginx configuration.
  2. Step 2: Identify missing semicolon

    The line listen 80 is missing a semicolon at the end.
  3. Final Answer:

    Missing semicolon after listen 80 -> Option A
  4. Quick Check:

    Every directive ends with ; [OK]
Hint: Check every line ends with semicolon [OK]
Common Mistakes:
  • Forgetting semicolon after directives
  • Placing listen inside location block incorrectly
  • Changing root path without reason
5. You want to serve a website on port 8080 with files located in /home/user/site and the main page named home.html. Which Nginx server block is correct?
hard
A. server { listen 8080; root /home/user/site; index home.html; }
B. server { listen 80; root /home/user/site; index home.html; }
C. server { listen 8080; root /var/www/html; index index.html; }
D. server { listen 8080; root /home/user/site; index index.html; }

Solution

  1. Step 1: Match the listen port

    The question requires port 8080, so listen 8080; is needed.
  2. Step 2: Match root and index directives

    Root must be /home/user/site and index must be home.html as given.
  3. Final Answer:

    server { listen 8080; root /home/user/site; index home.html; } -> Option A
  4. Quick Check:

    Port 8080 + correct root + correct index = server { listen 8080; root /home/user/site; index home.html; } [OK]
Hint: Match all three: listen, root, index exactly [OK]
Common Mistakes:
  • Using default port 80 instead of 8080
  • Wrong root folder path
  • Wrong index file name