nginx一直希望支持更多的脚本能力,现在js已纳入旗下。多余的不说了,直接尝鲜吧!
0. 安装
> cd /tmp && mkdir njs && cd njs
> wget http://nginx.org/download/nginx-1.8.0.tar.gz
> wget http://hg.nginx.org/njs/archive/tip.tar.gz && tar zxvf tip.tar.gz
> cd njs-3ed92ffa3f05 && ./configure && make
> cd .. && tar zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0
> ./configure --add-module=../njs-3ed92ffa3f05/nginx && make && make install
server {
listen 80;
location /njs {
js_run "
var res;
res = $r.response;
res.contentType = ‘text/plain‘;
res.status = 200;
res.sendHeader();
res.send( ‘Hello, world!‘ );
res.finish();
";
}
}
最后,启动访问,如此简单,赶快试下吧
原文:http://my.oschina.net/fqing/blog/511465