Skip to content

Use Case

Ryo Okubo edited this page Aug 25, 2016 · 8 revisions

Use Case

  • There are some examples on example/ directory.
  • You may replace some ATS plugins.

Hello world

  • unified_hello.rb
if server_name == "NGINX"
  Server = Nginx
elsif server_name == "Apache"
  Server = Apache
elsif server_name == "ApacheTrafficServer"
  Server = ATS

Server::rputs "Hello #{Server::module_name}/#{Server::module_version} world!"
# mod_mruby => "Hello mod_mruby/0.9.3 world!"
# ngx_mruby => "Hello ngx_mruby/0.0.1 world!"
# ts_mruby  => "Hello ts_mruby/0.0.1 world!"
  • remap.config
map /test @pparam=etc/trafficserver/unified_hello.rb

Load balancing

  • Randomize a target host of ATS origin server.
backends = [
upstream =
upstream.server = backends[rand(backends.length)]

Header rewriting (An alternative of Header Rewrite Plugin)

r =
conn =
r.headers_in["X-ATS-Plugin"] = "ts_mruby"
r.headers_in["X-Forwarded-For"] = conn.remote_ip

Regexp base reverse proxy rule (An alternative of Regex Remap Plugin)

req =
path = req.uri + req.args

if path =~ /^\/(ogre.*)\/bad/
elsif path =~ /^\/oldurl\/(.*)$/
  ATS::redirect '' + $1, ATS::HTTP_MOVED_TEMPORARILY

Flexible overriding configuratrions (An alternative of Configuration Remap Plugin)

  • Enable cache:
records =
records.set ATS::Records::TS_CONFIG_HTTP_CACHE_HTTP, 1

Change to maintenance mode with Redis

redis = '', 6789

if redis['ts_maint']
  body = <<'EOS'
    <title>Message from your proxy ...</title>
    <p>Sorry, maintainance mode now ...</p>
  ATS::echo body

Markdown Web Page

discount ="", "Markdown Web page example")
md = <<'EOS'
# Markdown Web page example

* You can write web pages by Markdown format.
* The doc will converted to html when HTTP requests come.

## Requirements

* [mruby-discount](

## Example

* This .rb file is it!

html = discount.header
html << discount.md2html(md)
html << discount.footer

ATS::rputs html

Image resizer


Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.