Help developing a block directive

Vladimir Homutov vl at nginx.com
Wed Jun 28 21:38:23 UTC 2017


On 29.06.2017 00:15, Joseph Spencer wrote:
> Hello,
> 
> I'm trying to support this in my nginx.conf:
> 
> my_custom_module_block {
>   directive_for_my_custom_module_block "Some value";
> }
> 
> Here is how I'm setting up the commands:
> 
>   static ngx_command_t ngx_my_custom_module_commands[] = {              
>                   
>       {                                                                
>                
>        ngx_string("my_custom_module_block"), /* directive */            
>                        
>         NGX_HTTP_SRV_CONF |                                            
>                
>         NGX_HTTP_LOC_CONF |                                            
>                
>         NGX_CONF_NOARGS |                                              
>                
>         NGX_CONF_BLOCK,                                                
>                
>         my_custom_module_block, /* configuration setup function */      
>               
>         0, /* No offset. Only one context is supported. */              
>               
>         0, /* No offset when storing the module configuration on struct.
> */            
>         NULL                                                            
>               
>       },                                                                
>               
>                                                                        
>               
>      {                                                                  
>              
>         ngx_string("directive_for_my_custom_module_block"), /* directive
> */                                      
>         NGX_CONF_TAKE1,                                                
>                
>         ngx_directive_for_my_custom_module_block_cmd, /* configuration
> setup function */                         
>         0, /* No offset. Only one context is supported. */              
>               
>         0, /* No offset when storing the module configuration on struct.
> */            
>         NULL                                                            
>               
>      },                                                                
>               
>                                                                        
>               
>       ngx_null_command /* command termination */                        
>               
>   };  
> 
> Everything compiles fine; however, I receive the following error and
> nginx won't start:
> 
> 2017/06/28 21:02:44 [emerg] 1#1: "directive_for_my_custom_module_block"
> directive is not allowed here in /etc/nginx/nginx.conf:19
> nginx: [emerg] "directive_for_my_custom_module_block" directive is not
> allowed here in /etc/nginx/nginx.conf:19
> 
> If anyone could be of assistance I would greatly appreciate it.
> 

Take a look at ngx_conf_file.h to understand which structure flags have.
You did not specify any possible context for the command that will
appear in your block: NGX_CONF_TAKE1 solo only describes number of
arguments, but command is not matching anything, thus the error.

You can either declare your own context, like ngx_http_upstream_module
does (NGX_HTTP_UPS_CONF for commands inside upstream{} block) or
use API from ngx_conf_file.h to process commands inside your block
like ngx_conf_handler() does.








More information about the nginx-devel mailing list