Skip to content
matsumoto-r edited this page Jul 6, 2012 · 61 revisions

Welcome to the mod_mruby wiki!

What's mod_mruby

mod_mruby - to provide an alternative to mod_lua.

Apache modules can be implemeted by mruby scripts on Apache HTTP Server installed mod_mruby.

How to use

Compile

make

Install

make install

Settings

  • Add to /usr/local/apache/conf/httpd.conf

      LoadModule mruby_module modules/mod_mruby.so
      # remove comment out if you use .mrb as Web contens
      # AddHandler mruby-script .mrb
    
    • hook mrb-script on ap_hook_translateName Middle phase

         mrubyTranslateNameMiddle /path/to/file.mrb
      

Apache Restart

/etc/init.d/httpd restart

Example

  • Selecting vhost area like mod_vhost_alias
    r = Apache::Request.new()
    s = Apache::Server.new()
    
    r.filename = s.docroot + "/" + r.hostname + "/" + r.uri
    
    Apache::return(Apache::OK)
  • Proxy balancer like mod_proxy_balancer
    backends = [
        "http://192.168.0.101:8888/",
        "http://192.168.0.102:8888/",
        "http://192.168.0.103:8888/",
        "http://192.168.0.104:8888/",
    ]
    
    # write balancing algorithm here.
    
    r = Apache::Request.new()
    
    r.handler  = "proxy-server"
    r.proxyreq = Apache::PROXYREQ_REVERSE
    r.filename = "proxy:" + backends[rand(backends.length)] + r.uri
    
    Apache::return(Apache::OK)

Test

Functions

Data Structure

Clone this wiki locally