Request transformation in nginx means changing parts of the incoming client request before sending it to the backend server. This can include modifying headers, URLs, or request bodies.
Click to reveal answer
intermediate
How can nginx modify response headers?
Nginx can modify response headers using the proxy_set_header directive for requests or the add_header directive for responses, allowing control over headers sent back to the client.
Click to reveal answer
intermediate
Which nginx module is commonly used for advanced request and response transformations?
The ngx_http_sub_module allows simple text substitutions in response bodies, and the ngx_http_rewrite_module helps rewrite URLs and headers.
Click to reveal answer
beginner
What does the proxy_set_header directive do?
It sets or changes headers in the request sent from nginx to the backend server, allowing you to add or modify headers before forwarding the request.
Click to reveal answer
intermediate
How can you rewrite a URL path in nginx before proxying?
You can use the rewrite directive inside a location block to change the URL path, for example: rewrite ^/oldpath/(.*)$ /newpath/$1 break;.
Click to reveal answer
Which nginx directive is used to change request headers before sending to the backend?
Asub_filter
Badd_header
Crewrite
Dproxy_set_header
✗ Incorrect
The proxy_set_header directive modifies headers in the request sent to the backend server.
What does the nginx add_header directive do?
AAdds or modifies response headers
BRewrites URL paths
CModifies request headers
DSubstitutes text in response body
✗ Incorrect
add_header adds or modifies headers in the response sent back to the client.
Which module allows simple text replacement in nginx response bodies?
Angx_http_rewrite_module
Bngx_http_sub_module
Cngx_http_proxy_module
Dngx_http_headers_module
✗ Incorrect
The ngx_http_sub_module enables text substitution in response bodies.
How do you rewrite a URL path in nginx?
AUsing rewrite directive
BUsing add_header
CUsing proxy_set_header
DUsing sub_filter
✗ Incorrect
The rewrite directive changes the URL path before proxying.
What happens if you use proxy_set_header Host $host; in nginx?
AAdds a new header named Host with value $host
BRemoves the Host header
CSets the Host header to the original client host
DDoes nothing
✗ Incorrect
It sets the Host header in the proxied request to the value of the original client host.
Explain how nginx can transform both incoming requests and outgoing responses.
Think about directives like proxy_set_header, rewrite, add_header, and sub_filter.
You got /4 concepts.
Describe a simple nginx configuration snippet that rewrites a URL path and changes a request header before proxying.
Use rewrite to change URL, proxy_set_header to modify headers, and proxy_pass to forward.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of request/response transformation in nginx?
easy
A. To block all incoming requests
B. To increase the server's hardware capacity
C. To change the server's IP address automatically
D. To modify data passing through nginx for better communication
4. You want to modify the response body in nginx but changes don't appear. What is the likely cause?
medium
A. gzip compression is enabled, preventing body modification
B. proxy_pass directive is missing
C. add_header directive is used incorrectly
D. server block is missing listen directive
Solution
Step 1: Understand response body modification requirements
Modifying response body requires disabling gzip compression because compressed data can't be changed easily.
Step 2: Identify common misconfigurations
If gzip is enabled, changes won't show; proxy_pass or listen missing causes other errors, add_header affects headers only.
Final Answer:
gzip compression is enabled, preventing body modification -> Option A
Quick Check:
Disable gzip to modify response body [OK]
Hint: Disable gzip to allow response body changes [OK]
Common Mistakes:
Ignoring gzip compression effect
Confusing header directives with body changes
Assuming missing proxy_pass causes this issue
5. You want to rewrite incoming URLs from /old-path/ to /new-path/ and add a response header X-Updated: true. Which nginx config snippet correctly does both?
places rewrite after proxy_pass (ignored). Configs using location /new-path/ have the wrong location. Configs with permanent cause redirects, not internal rewrites.