server {
listen 80;
}
server {
listen 443;
}
*/
// blocks with values:
conf.nginx.http.server[1]._add('location', '/');
conf.nginx.http.server[1].location._add('root', '/var/www/example.com');
/*
server {
location / {
root /var/www/example.com;
}
}
*/
// lua blocks also work, but you can't put a mismatched "{" or "}" in a comment!
conf.nginx.http.location._addVerbatimBlock('rewrite_by_lua_block', '{n
ngx.say("this is a lua block!")n
res = ngx.location.capture("/memc",n
{ args = { cmd = "incr", key = ngx.var.uri } }n
)n
}');
});
此工具同样支持对注释的修改
// 读取use配置上的注释,以数组的方式返回
console.log(conf.nginx.events.use._comments.length); // 1
console.log(conf.nginx.events.use._comments[0]); // use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
// 删除注释
conf.nginx.events.use._comments.splice(0, 1);
// 添加注释
conf.nginx.event.use._comments.push('my new comment');
console.log(conf.nginx.events.use._comments.length); // 1
console.log(conf.nginx.events.use._comments[0]); //my new comment
// 修改注释
conf.nginx.event.use._comments[0] = 'updated';
console.log(conf.nginx.events.use._comments[0]); //updated注意特殊情况
foo #comment
bar;
console.log(conf.nginx.foo._value); //bar
console.log(conf.nginx.foo._comments[0]); //comment
But if the comment comes after:
foo bar;
#comment
console.log(conf.nginx.foo._value); //bar
console.log(conf.nginx.foo._comments.length); //0希望本文所述对大家node.js程序设计有所帮助。









