Dynamically update nginx configuration files via programmatic API
nginx-conf is a node module for making changes to an nginx configuration
npm install nginx-conf
Pretend you have an nginx config file like this one.
Note that all public methods are prefixed with
_ so that they (hopefully) don't clash with
var NginxConfFile = NginxConfFile;NginxConfFile;
Support for comments is supported-ish. Comments are attached to directives, and will always
be rendered above the directive when using
Comments can be added, removed and updated via the
_comments array on a node.
console; // 1console; // use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];//remove the commentconfnginxeventsuse_comments;//add a new oneconfnginxeventuse_comments;console; // 1console; //my new comment//update a comment's textconfnginxeventuse_comments0 = 'updated';console; //updated
If the comment is in a weird place (like in the middle of a directive), it'll still be attached to the node. If it's after the directive (after the semicolon or closing brace), it will be attached to the next node, or ignored if it's at the end of the file.
Assuming this nginx configuration:
You will have this object structure:
console; //barconsole; //comment
But if the comment comes after:
console; //barconsole; //0
git clone firstname.lastname@example.org:tmont/nginx-conf.gitcd nginx-confnpm installnpm test