Bird
Raised Fist0
Nginxdevops~10 mins

Why reverse proxying serves backend applications in Nginx - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the server listening on port 80.

Nginx
server {
    listen [1];
    server_name example.com;
}
Drag options to blanks, or click blank then click option'
A80
B443
C22
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 without SSL configuration
Using SSH port 22 instead of HTTP port
2fill in blank
medium

Complete the code to forward requests to the backend server at localhost port 3000.

Nginx
location / {
    proxy_pass http://[1];
}
Drag options to blanks, or click blank then click option'
A127.0.0.1:80
Blocalhost:22
C127.0.0.1:3000
D192.168.1.1:3000
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port number
Using external IP instead of localhost
3fill in blank
hard

Fix the error in the proxy_pass directive to correctly forward to backend.

Nginx
location /api/ {
    proxy_pass http://127.0.0.1[1]3000/;
}
Drag options to blanks, or click blank then click option'
A.
B/
C;
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using slash instead of colon between IP and port
Omitting the port separator
4fill in blank
hard

Fill both blanks to set headers that preserve the original client IP and host.

Nginx
location / {
    proxy_set_header [1] $remote_addr;
    proxy_set_header [2] $host;
}
Drag options to blanks, or click blank then click option'
AX-Real-IP
BHost
CX-Forwarded-For
DServer-Name
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect header names
Not setting headers to preserve client info
5fill in blank
hard

Fill both blanks to create a reverse proxy that listens on port 80, forwards to backend at 5000, and sets the correct headers.

Nginx
server {
    listen [1];
    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header [2] $remote_addr;
    }
}
Drag options to blanks, or click blank then click option'
A80
B:
CX-Real-IP
D443
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port in listen directive
Missing colon between IP and port
Not setting client IP header

Practice

(1/5)
1. What is the main purpose of using a reverse proxy like nginx for backend applications?
easy
A. To store user data permanently
B. To replace the backend application entirely
C. To act as a middleman between users and backend servers
D. To directly expose backend servers to the internet

Solution

  1. Step 1: Understand the role of a reverse proxy

    A reverse proxy sits between users and backend servers, forwarding requests and responses.
  2. Step 2: Identify the main purpose

    It improves security and performance by hiding backend details and managing traffic.
  3. Final Answer:

    To act as a middleman between users and backend servers -> Option C
  4. Quick Check:

    Reverse proxy = Middleman [OK]
Hint: Reverse proxy = middleman between user and backend [OK]
Common Mistakes:
  • Thinking reverse proxy replaces backend apps
  • Assuming it stores user data
  • Believing it exposes backend directly
2. Which nginx directive is used to forward client requests to a backend server in reverse proxy setup?
easy
A. proxy_pass
B. server_name
C. listen
D. root

Solution

  1. Step 1: Identify nginx directives related to proxying

    The directive that forwards requests to backend servers is proxy_pass.
  2. Step 2: Differentiate from other directives

    server_name sets domain, listen sets port, root sets file path.
  3. Final Answer:

    proxy_pass -> Option A
  4. Quick Check:

    Forward requests = proxy_pass [OK]
Hint: proxy_pass forwards requests to backend [OK]
Common Mistakes:
  • Confusing proxy_pass with server_name
  • Using listen to forward requests
  • Mistaking root for proxying
3. Given this nginx config snippet, what happens when a user accesses http://example.com/api/?
location /api/ {
    proxy_pass http://backend_server/;
}
medium
A. Requests to /api/ are forwarded to http://backend_server/
B. Requests to /api/ are forwarded to http://backend_server/api/
C. Requests to /api/ are served from nginx root directory
D. Requests to /api/ cause a 404 error

Solution

  1. Step 1: Understand proxy_pass behavior with trailing slash

    When proxy_pass URL ends with a slash, nginx replaces the matching part of the request URI.
  2. Step 2: Apply to given config

    Request to /api/ is forwarded to backend_server root /, so /api/ is replaced by /.
  3. Final Answer:

    Requests to /api/ are forwarded to http://backend_server/ -> Option A
  4. Quick Check:

    proxy_pass with trailing slash replaces matching URI [OK]
Hint: Trailing slash in proxy_pass replaces matching URI part [OK]
Common Mistakes:
  • Assuming URI is appended instead of replaced
  • Thinking nginx serves files locally
  • Expecting 404 without backend
4. You configured nginx as a reverse proxy but get a 502 Bad Gateway error. Which is the most likely cause?
medium
A. server_name directive is incorrect
B. proxy_pass directive is missing a semicolon
C. nginx is listening on the wrong port
D. Backend server is down or unreachable

Solution

  1. Step 1: Understand 502 Bad Gateway meaning

    502 means nginx cannot connect to the backend server to get a valid response.
  2. Step 2: Identify common causes

    The backend server being down or unreachable is the most common cause of 502 errors.
  3. Final Answer:

    Backend server is down or unreachable -> Option D
  4. Quick Check:

    502 error = backend unreachable [OK]
Hint: 502 error usually means backend server unreachable [OK]
Common Mistakes:
  • Blaming missing semicolon for 502 error
  • Confusing port listen issues with backend errors
  • Assuming server_name causes 502
5. You want nginx to serve static files directly but forward API requests to a backend app. Which config snippet correctly achieves this?
hard
A. location / { proxy_pass http://backend/; } location /api/ { root /var/www/html; }
B. location /api/ { proxy_pass http://backend/; } location / { root /var/www/html; }
C. location /api/ { root /var/www/html; } location / { proxy_pass http://backend/; }
D. location / { root /var/www/html; proxy_pass http://backend/; }

Solution

  1. Step 1: Separate static and API requests

    Static files should be served from nginx root for /, API requests proxied under /api/.
  2. Step 2: Check config snippet correctness

    location /api/ { proxy_pass http://backend/; } location / { root /var/www/html; } correctly proxies /api/ to backend and serves / from local files.
  3. Final Answer:

    location /api/ { proxy_pass http://backend/; } location / { root /var/www/html; } -> Option B
  4. Quick Check:

    Static on /, API on /api/ with proxy_pass [OK]
Hint: Proxy API path, serve static root separately [OK]
Common Mistakes:
  • Reversing proxy and root locations
  • Combining proxy_pass and root in same block
  • Serving API requests from root directory
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard