Skip to content
matsumoto-r edited this page Sep 9, 2014 · 27 revisions

Quick Install using Docker

Use docker images example

docker run -d --name name1 matsumotory/mod-mruby
docker run -d --name name2 matsumotory/mod-mruby
docker run -d --name name3 matsumotory/mod-mruby
docker run -d -p 80:80 --link name1:proxy1 --link name2:proxy2 --link name3:proxy3 matsumotory/ngx-mruby
curl http://127.0.0.1/mruby-proxy

Use docker build

git clone git@github.com:matsumoto-r/mod_mruby.git
cd mod_mruby
# Edit apache config and Ruby script
vi docker/conf/mruby.conf
vi docker/hook/$(your_script).rb
docker build -t local/mod-mruby .
docker run -d -p 80:80 local/mod-mruby
curl http://127.0.0.1/mruby-hello

Others

Install

1. Download

git clone git://github.com/matsumoto-r/mod_mruby.git

2. Test for your environment

Downloading latest Apache httpd and test mod_mruby in your environment.

cd mod_mruby
sh test.sh

Please see test page if you want to know more details

3. Auto Build

sh build.sh
Or set apxs or apachectl path
APXS_PATH_ENV='--with-apxs=/usr/local/apache/bin/apxs' \
APACHECTL_PATH_ENV='--with-apachectl=/usr/local/apache/bin/apachectl' \
sh build.sh

4. Test Settings for installed mod_mruby

  • Add to httpd.conf or conf.d/mruby.conf
    LoadModule mruby_module modules/mod_mruby.so
    <Location /mruby-test>
        mrubyHandlerMiddle /path/to/test.rb
    </Location>

or cache enabled apache LoadModule mruby_module modules/mod_mruby.so <Location /mruby-test> mrubyHandlerMiddle /path/to/test.rb cache </Location>

  • test.rb copy

      cp -p test/test.rb /path/to/test.rb
    

5. Apache Restart

service httpd restart

6. Access URL by Browser

curl http://127.0.0.1/mruby-test

Manual Build

  • mruby/mruby build

      cd mod_mruby
      git submodule init
      git submodule update
      cd mruby
      rake
      cd ..
    
  • configure

      ./configure
    
  • using mruby/mruby

      make
      make install
    

Example

  • Selecting vhost area like mod_vhost_alias(hook on translatename)
    r = Apache::Request.new()
    s = Apache::Server.new()
    
    r.filename = s.document_root + "/" + r.hostname + "/" + r.uri
    
    Apache::return(Apache::OK)
  • Proxy balancer like mod_proxy_balancer(hook on translatename)
    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)

Notes

  • We should implement ngx_mruby/mod_mruby extensions as mrbgems, as possible.
  • We recommend the contribute to mruby by implementing mrbgems.