0
0
Expressframework~20 mins

Nginx as reverse proxy in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Reverse Proxy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when Nginx is set as a reverse proxy for an Express app?

Consider an Express app running on port 3000. Nginx is configured to forward requests from port 80 to this app. What is the visible effect when a user accesses the server's IP on port 80?

Express
server {
  listen 80;
  location / {
    proxy_pass http://localhost:3000;
  }
}
AThe user sees the Express app response as if directly accessing port 3000.
BThe user gets a 404 error because Nginx blocks all requests.
CThe user sees the Nginx default welcome page instead of the Express app.
DThe user is redirected to port 3000 in the browser URL.
Attempts:
2 left
💡 Hint

Think about what a reverse proxy does with incoming requests.

📝 Syntax
intermediate
1:30remaining
Identify the correct Nginx proxy_pass syntax for forwarding to Express

Which Nginx configuration snippet correctly forwards all requests to an Express app running on localhost port 4000?

Alocation / { proxy_pass http://:4000; }
Blocation / { proxy_pass localhost:4000; }
Clocation / { proxy_pass http://localhost4000; }
Dlocation / { proxy_pass http://localhost:4000; }
Attempts:
2 left
💡 Hint

Remember the full URL format for proxy_pass.

🔧 Debug
advanced
2:30remaining
Why does the Express app receive incorrect client IP behind Nginx reverse proxy?

An Express app behind Nginx reverse proxy logs the client IP as 127.0.0.1 instead of the real user IP. What is the cause?

ANginx is not forwarding the original client IP in the X-Forwarded-For header.
BExpress app is not listening on the correct port.
CNginx is caching the responses causing IP mismatch.
DExpress app has a syntax error in the logging middleware.
Attempts:
2 left
💡 Hint

Think about how proxies pass client IP information.

state_output
advanced
2:00remaining
What is the value of req.protocol in Express behind Nginx reverse proxy with HTTPS?

Nginx terminates HTTPS and proxies requests to Express over HTTP. In Express, what is the value of req.protocol by default?

AThrows an error due to protocol mismatch.
B"https" because the original request was HTTPS.
C"http" because Express receives plain HTTP from Nginx.
DUndefined because protocol is not set.
Attempts:
2 left
💡 Hint

Consider what Express actually receives from Nginx.

🧠 Conceptual
expert
3:00remaining
How to correctly configure Express to trust Nginx reverse proxy for secure cookies?

You want to set secure cookies in Express behind Nginx reverse proxy that terminates HTTPS. Which Express setting ensures cookies are marked secure correctly?

ASet <code>app.set('trust proxy', false)</code> to disable proxy trust.
BSet <code>app.set('trust proxy', 1)</code> to trust the first proxy.
CSet <code>app.enable('trust proxy')</code> without arguments.
DNo Express setting needed; Nginx handles cookies.
Attempts:
2 left
💡 Hint

Think about how Express determines if a request is secure behind a proxy.