Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nginx + mrubyを動かす / run the ngx_mruby

Nginx + mrubyを動かす / run the ngx_mruby

Takeshi Kondo

May 23, 2018
Tweet

More Decks by Takeshi Kondo

Other Decks in Technology

Transcript

  1. /HJOY w ΞΫηε੍ޚ w 63*3FXSJUF w H[JQѹॖ w ϦόʔεϓϩΩγ w

    -ϩʔυόϥϯε w ίϯςϯπΩϟογϡ w 44-λʔϛωʔγϣϯɺ)551ήʔτ΢ΣΠ w -ʢ5$1ʣϩʔυόϥϯε w ϝʔϧϓϩΩγ OHJOY࣮ફೖ໳OHJOY
  2. /HJOY w ΞΫηε੍ޚ w 63*3FXSJUF w H[JQѹॖ w ϦόʔεϓϩΩγ w

    -ϩʔυόϥϯε w ίϯςϯπΩϟογϡ w 44-λʔϛωʔγϣϯɺ)551ήʔτ΢ΣΠ w -ʢ5$1ʣϩʔυόϥϯε w ϝʔϧϓϩΩγ OHJOY࣮ફೖ໳OHJOY ͳΜͰ΋Ͱ͖͗͢
  3. /HJOYͷϑΣʔζͱϑοΫϙΠϯτ mruby nginx આ໌ mruby_server_rewrite_handle server rewrite αʔόίϯςΩετͷrewrite find config

    ֘౰͢Δlocation configΛ୳͢ mruby_rewrite_handler rewrite locationͷrewriteॲཧ post rewrite pre-access mruby_access_handler access ϑΝΠϧ΁ͷΞΫηε post-access try-files try_filesͷॲཧ mruby_content_handler content bodyͷੜ੒ mruby_log_handler log ϩάॻ͖ࠐΈ )551SFRVFTUQSPDFTTJOHQIBTFTJO/HJOYIUUQXXXOHJOYHVUTDPNQIBTFT
  4. ͜͜ʹp[[CV[[͕͋Δ͡ΌΖʁ r = Nginx::Request.new n = r.var.arg_n.to_i if n %

    15 == 0 ans = "FizzBuzz" elsif n % 3 == 0 ans = "Fizz" elsif n % 5 == 0 ans = "Buzz" else ans = n end Nginx.echo(ans) ʢ΅΍͖ʣIJHIMJHIU࢖͚ͬͨͲΠϚΠνͩͳʜ
  5. OHJOYDPOG http { server { location /fizzbuzz { mruby_content_handler /usr/local/nginx/conf/fizzbuzz.rb;

    } location /redirect { mruby_rewrite_handler_code ' Nginx.redirect "/fizzbuzz", Nginx::HTTP_MOVED_PERMANENTLY '; } } }