Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx how to access variables from one module from another module?

Tags:

c

nginx

There are 2 self-written nginx modules, a data output module and a module that contains actual data. It is necessary initialize the pointer that is located in the output module from the module that contains the actual data. Initialize this pointer with the address to a variable with actual data (which periodically changes its value), so at the time of data output, dereferencing the pointer, show (output) actual data.

like image 656
vasiliy Avatar asked Oct 25 '25 13:10

vasiliy


1 Answers

use ngx_http_add_variable to create the "shared" variable, which should return a ngx_http_variable_t which has ngx_http_set_variable_pt and ngx_http_get_variable_pt function pointer to set a value.

The second module should use ngx_http_get_variable to retreive the variable and use the respective ngx_http_set_variable_pt and ngx_http_get_variable_pt

please refer to the njs sources at the following position for adding a variable and for getting a variable for examples

like image 92
dvhh Avatar answered Oct 27 '25 02:10

dvhh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!