Nginx + mrubyを動かす / run the ngx_mruby

Nginx + mrubyを動かす / run the ngx_mruby

93c80c388fe9d8f9df7d030549a0ff0b?s=128

Takeshi Kondo

May 23, 2018
Tweet

Transcript

  1. 5.

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

    -ϩʔυόϥϯε w ίϯςϯπΩϟογϡ w 44-λʔϛωʔγϣϯɺ)551ήʔτ΢ΣΠ w -ʢ5$1ʣϩʔυόϥϯε w ϝʔϧϓϩΩγ OHJOY࣮ફೖ໳OHJOY
  2. 6.

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

    -ϩʔυόϥϯε w ίϯςϯπΩϟογϡ w 44-λʔϛωʔγϣϯɺ)551ήʔτ΢ΣΠ w -ʢ5$1ʣϩʔυόϥϯε w ϝʔϧϓϩΩγ OHJOY࣮ફೖ໳OHJOY ͳΜͰ΋Ͱ͖͗͢
  3. 9.

    /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. 11.

    ͜͜ʹ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. 12.

    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 '; } } }