/hello?location /hello {
default_type text/plain;
return 200 'Hello, NGINX!';
}return directive and the default_type setting.The return 200 'Hello, NGINX!'; directive sends a 200 status with the given plain text body. The default_type text/plain; ensures the Content-Type header is text/plain.
/old-path to /new-path without redirecting the client. Which option achieves this?The rewrite ... break; directive rewrites the URI internally without telling the client. The return 301 and rewrite ... redirect; cause client redirects. proxy_pass forwards requests to a backend, not a rewrite.
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?The sub_filter module only modifies response bodies with Content-Type headers matching text/html or similar by default. If the backend sends application/json or others, sub_filter won't change the body unless configured.
/api/v1 to /v1/api and add a custom response header X-Custom: true:First, define the location block (4). Then rewrite the URI internally (1). Next, proxy the request to backend (3). Finally, add the custom response header (2) which modifies the response before sending to client.
Using sub_filter risks breaking JSON if replacements are partial or affect syntax. proxy_set_header only changes headers, not body. rewrite changes request URIs, not response bodies. Lua scripting allows safe parsing and modification of JSON content.