CoreMethods

mruby_nginx_module's core methods are following.

Nginx.rputs

Nginx.rputs add string-argument to output-buffer-chain for a response. Following is the example for mruby_nginx_module's "Hello, World!".

location /hello_world {
    mruby_content_handler_code '
        Nginx.rputs("Hello, World!\n")
        Nginx.return Nginx::HTTP_OK
    ';
}

Return HTTP_OK(200) when Nginx.rputs is called. If Nginx.return is skipped, HTTP_OK(200) is set automatically.

Nginx.return

Nginx.return sets the http status code for a response.

Nginx.rputs("Hello, World!\n")
Nginx.return Nginx::HTTP_OK

Nginx.return does not terminate to execute a mruby script. So not call Nginx.return more than once.

Nginx.log

Nginx.log outputs a message to error.log.

Nginx.log(Nginx::LOG_ERR, "error message")

Nginx.module_version

Nginx.module_version returns the version of mruby_nginx_module.

Nginx.module_version # => 0.1.1

Nginx.version

Nginx.version returns the version of nginx.

Nginx.version # => 1.5.4

Nginx.redirect

Nginx.redirect returns a redirection response.

Nginx.redirect "http://localhost:8000/hello", 301

If the redirect-uri is internal, Nginx.redirect redirects internally.

Nginx.redirect "/hello", 301