0
0
Nginxdevops~20 mins

Request/response transformation in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Request/Response Transformer
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this NGINX configuration snippet?
Given the following NGINX configuration, what will be the response body when a client requests /hello?
Nginx
location /hello {
    default_type text/plain;
    return 200 'Hello, NGINX!';
}
AThe client receives a plain text response with body: Hello, NGINX!
BThe client receives a JSON response with body: {"message": "Hello, NGINX!"}
CThe client receives an empty response with status 200
DThe client receives a 404 Not Found error
Attempts:
2 left
💡 Hint
Look at the return directive and the default_type setting.
Configuration
intermediate
2:00remaining
Which configuration correctly rewrites the request URI from /old-path to /new-path internally?
You want NGINX to internally rewrite requests from /old-path to /new-path without redirecting the client. Which option achieves this?
A
location /old-path {
    rewrite ^/old-path$ /new-path break;
}
B
location /old-path {
    return 301 /new-path;
}
C
location /old-path {
    proxy_pass http://backend/new-path;
}
D
location /old-path {
    rewrite ^/old-path$ /new-path redirect;
}
Attempts:
2 left
💡 Hint
Consider the difference between internal rewrite and client redirect.
Troubleshoot
advanced
2:00remaining
Why does this NGINX config not modify the response body as expected?
You want to replace all occurrences of 'foo' with 'bar' in the response body using this config:
location / {
    sub_filter 'foo' 'bar';
    sub_filter_once off;
    proxy_pass http://backend;
}
But the response body remains unchanged. What is the most likely cause?
AThe <code>proxy_pass</code> URL is incorrect and backend is unreachable
BThe <code>sub_filter</code> module only works with <code>proxy_set_header</code> directives
CThe response Content-Type header is not one of the types <code>sub_filter</code> modifies by default
DThe <code>sub_filter_once off;</code> directive disables all substitutions
Attempts:
2 left
💡 Hint
Check the Content-Type header of the response from backend.
🔀 Workflow
advanced
2:00remaining
What is the correct order of directives to transform a request URI and modify response headers in NGINX?
Arrange these steps in the correct order to transform a request URI from /api/v1 to /v1/api and add a custom response header X-Custom: true:
A4,3,1,2
B4,2,1,3
C1,4,3,2
D4,1,3,2
Attempts:
2 left
💡 Hint
Think about how NGINX processes requests and responses in order.
Best Practice
expert
3:00remaining
Which approach is best to safely transform JSON response bodies in NGINX without breaking the JSON structure?
You want to replace a specific field value in JSON responses from your backend. Which method is safest and most reliable?
AUse <code>sub_filter</code> to replace the field value as plain text in the response body
BUse a Lua script with <code>ngx_http_lua_module</code> to parse and modify JSON before sending
CUse <code>proxy_set_header</code> to modify the JSON response headers
DUse <code>rewrite</code> directive to change the JSON response body
Attempts:
2 left
💡 Hint
Consider JSON structure and how text replacement might affect it.