読者です 読者をやめる 読者になる 読者になる

mruby-hibari を ngx_mruby で (ry

こんなお言葉をいただいたのでとりあえず ngx_mruby を

$ git clone git@github.com:matsumoto-r/ngx_mruby.git
$ cd ngx_mruby

build_config.rb に mruby-hibari を追加

$ git diff
diff --git a/build_config.rb b/build_config.rb
index 2d7d1bf..7dc33ec 100644
--- a/build_config.rb
+++ b/build_config.rb
@@ -46,5 +46,6 @@ MRuby::Build.new do |conf|
   # Linux only for ngx_mruby
   # conf.gem :github => 'matsumoto-r/mruby-capability'
   # conf.gem :github => 'matsumoto-r/mruby-cgroup'
+  conf.gem :github => 'kentaro/mruby-hibari'

build して make して install

$ sh build.sh && make && make install

config ファイルを書き換え

 diff -u build/nginx/conf/nginx.conf.default build/nginx/conf/nginx.conf
--- build/nginx/conf/nginx.conf.default 2015-09-20 15:18:40.000000000 +0900
+++ build/nginx/conf/nginx.conf 2015-09-20 16:20:03.000000000 +0900
@@ -33,7 +33,7 @@
     #gzip  on;

     server {
-        listen       80;
+        listen       8080;
         server_name  localhost;

         #charset koi8-r;
@@ -45,6 +45,21 @@
             index  index.html index.htm;
         }

+        location /mruby {
+            mruby_content_handler_code '
+
+            hibari do
+              res.code = 200
+              res.headers["content-type"] = "text/html; charset=utf8"
+              res.body.push("Hello, World!")
+              req.params.each do |k,v|
+                res.body.push("#{k}: #{v}")
+              end
+            end
+
+            ';
+        }
+
         #error_page  404              /404.html;

         # redirect server error pages to the static page /50x.html

server 起動して /mruby にアクセス

$ ./build/nginx/sbin/nginx
$ curl http://localhost:8080/mruby?hoge=fuga
Hello, World!hoge: fuga

出来た!

ちなみに mruby_content_handler ってフルパス指定じゃないとダメなんでしょうか?