Is it possible to configure Nginx to return a response body created from a request header, or a request parameter? It looks like this can be done with the echo
module, but if possible I would like to do it with a vanilla install of Nginx.
Basically I want to do the following, but obviously return_body
doesn't exist, so what can I use instead?
location ~* ^/echo/(.+) {
return_body $1;
}
or
location /echo_user_agent {
return_body $http_user_agent;
}
If I install the echo
module I could replace return_body
with echo
, but if at all possible it would be nice to be able to do this without having to install any extras, it seems to me like something simple like this should be possible to do without.
You can do this with return 200:
location = /echo_user_agent {
return 200 $http_user_agent;
}
Use ngx_lua module
.
Like this:
body_filter_by_lua 'ngx.log(ngx.CRIT,ngx.arg[1])';
in the right location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With