0
0
Nginxdevops~20 mins

Proxy headers in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Proxy Headers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the effect of this Nginx proxy header configuration?
Given the following Nginx snippet inside a location block, what will be the value of the X-Forwarded-For header sent to the upstream server if the client IP is 192.168.1.10 and the original X-Forwarded-For header was 10.0.0.1?
Nginx
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
AX-Forwarded-For: 10.0.0.1, 192.168.1.10
BX-Forwarded-For: 192.168.1.10
CX-Forwarded-For: 192.168.1.10, 10.0.0.1
DX-Forwarded-For: 10.0.0.1
Attempts:
2 left
💡 Hint
Think about how $proxy_add_x_forwarded_for appends the client IP to the existing header.
🧠 Conceptual
intermediate
1:30remaining
Why is setting the Host header important in Nginx proxying?
When proxying requests with Nginx, why should you explicitly set the Host header using proxy_set_header Host $host;?
ATo disable caching on the upstream server.
BTo hide the client IP address from the upstream server.
CTo encrypt the request headers between Nginx and the upstream.
DTo ensure the upstream server receives the original requested hostname for proper routing or virtual hosting.
Attempts:
2 left
💡 Hint
Think about how web servers use the Host header to decide which site to serve.
Troubleshoot
advanced
2:00remaining
Why is the client IP not appearing correctly in the upstream logs?
You configured Nginx as a reverse proxy with this header:
proxy_set_header X-Real-IP $remote_addr;
But the upstream server logs show the proxy server's IP instead of the client IP. What is the most likely cause?
AThe <code>proxy_set_header</code> directive is syntactically incorrect.
BThe upstream server is not configured to log the <code>X-Real-IP</code> header and logs the connection IP instead.
CThe client IP is blocked by Nginx and replaced with the proxy IP.
DThe <code>X-Real-IP</code> header is overwritten by the client.
Attempts:
2 left
💡 Hint
Check how the upstream server obtains the client IP for logging.
Best Practice
advanced
1:30remaining
Which proxy header configuration best preserves the original client IP chain?
You want to forward the full chain of client IPs through Nginx to the upstream server. Which configuration is best?
Aproxy_set_header X-Forwarded-For '';
Bproxy_set_header X-Forwarded-For $remote_addr;
Cproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Dproxy_set_header X-Forwarded-For $http_x_forwarded_for;
Attempts:
2 left
💡 Hint
Consider how to append the new client IP to existing forwarded IPs.
🔀 Workflow
expert
3:00remaining
Order the steps to correctly configure Nginx to forward client IPs to an upstream server behind a load balancer.
Arrange these steps in the correct order to ensure the upstream server receives the real client IP when Nginx is behind a load balancer.
A2,1,3,4
B3,2,1,4
C2,3,1,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about the data flow from client to load balancer, then Nginx, then upstream.