Is it possible to change the value of the request header as the response body using vanilla Nginx?

Is it possible to configure Nginx to return the body of the response created from the request header or request parameter? It looks like it can be done using the echo module, but if possible, I would like to do it using the Nginx vanilla installation.

Basically I want to do the following, but obviously return_body does not 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 installing any additional functions, it seems to me that something kind of simple, like this, you can do without .

+6
source share
3 answers

You can do this with return 200:

 location = /echo_user_agent { return 200 $http_user_agent; } 
+10
source

Use the ngx_lua module .

Like this:

 body_filter_by_lua 'ngx.log(ngx.CRIT,ngx.arg[1])'; 

in the right place.

+2
source

try this add_header Path_Way1; eg.

 add_header Path_Way1 $1; 

where $ 1 is the first parameter of the path

0
source

Source: https://habr.com/ru/post/903746/


All Articles