Create a variable value for nginx

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.