Where to store global settings in filter

Maxim Dounin mdounin at mdounin.ru
Mon Aug 25 13:20:27 UTC 2014


On Mon, Aug 25, 2014 at 10:55:06AM +0800, Jerry OELoo wrote:

> Hi All:
> I have some settings in a json file (not in nginx.conf file),
> Currently, in my module filter function, I will open file, read file,
> close file every time filter function is called.
> I think this is not so good, so I think it's better call a function
> just one time, and save the setting in a global variable, but I do not
> where is a proper position in Nginx module, Thanks!

It may be a good idea to read the json file while parsing 
configuration.  Such things are usually done either when 
processing a directive which specifies a file to use, or in a 
configuration merge callback.

E.g., XSLT filter loads stylesheets specified in the 
ngx_http_xslt_stylesheet() function, which is called to handle the 
"xslt_stylesheet" directive.  See 
src/http/modules/ngx_http_xslt_filter_module.c for details.

Maxim Dounin

More information about the nginx mailing list