Purpose: Create a variable in the nginx module and assign a value. The value can be obtained directly through the variable value in the configuration file.
1. In the readconf stage, insert the variable value:
Save the corresponding index value and use it later. Value [1] is the name of the variable.
Ngx_http_variable_t * V; Ngx_int_t index;
Ngx_str_t * value;
Value = static_cast <ngx_str_t *> (CF-> ARGs-> ELTs );
V = ngx_http_add_variable (CF, & value [1], ngx_http_var_changeable );
If (V = NULL ){
Return (char *) ngx_conf_error;
}
Index = ngx_http_get_variable_index (CF, & value [1]);
If (Index = ngx_error ){
Return (char *) ngx_conf_error;
} 2. Use the following Code : Ngx_http_core_main_conf_t * colap;
Ngx_http_variable_value_t * V;
Corganized = (ngx_http_core_main_conf_t *) ngx_http_get_module_main_conf (R, ngx_http_core_module );
V = ngx_http_get_indexed_variable (R, v_index );
If (R-> variables = NULL)
Printf ("variables null \ n ");
V-> Len = ilen;
V-> valid = 1;
V-> no_cacheable = 0;
V-> not_found = 0; change V-> data to the variable value.