LoginSignup
1
1

More than 5 years have passed since last update.

Nginxでmrubyを使ってredirectする時にログが出ない問題

Last updated at Posted at 2017-02-07
nginx.conf
    log_format redirect_local_ltsv 
        'domain:$host\t'
        'host:$http_x_forwarded_for\t'
        'time:$time_local\t'
        'etag:$http_etag\t'
        'etag?:$http_if_none_match\t'
        'msec:$msec\t'
    ;

    log_format redirect_absolute_ltsv 
        'domain:$host\t'
        'host:$http_x_forwarded_for\t'
        'time:$time_local\t'
        'etag:$http_etag\t'
        'etag?:$http_if_none_match\t'
        'msec:$msec\t'
    ;

    log_format redirect_google_ltsv 
        'domain:$host\t'
        'host:$http_x_forwarded_for\t'
        'time:$time_local\t'
        'etag:$http_etag\t'
        'etag?:$http_if_none_match\t'
        'msec:$msec\t'
    ;

    server {
        listen       80;

        location /index.html {
            root /Users/shinichiro/;
        }

        location ~ /redirect_local/ {
            access_log logs/redirect_local_ltsv.log redirect_local_ltsv;
            mruby_access_handler /Users/shinichiro/redirect_local.rb;
        }

        location ~ /redirect_absolute/ {
            access_log logs/redirect_absolute_ltsv.log redirect_absolute_ltsv;
            mruby_access_handler /Users/shinichiro/redirect_absolute.rb;
        }

        location ~ /redirect_google/ {
            access_log logs/redirect_google_ltsv.log redirect_google_ltsv;
            mruby_access_handler /Users/shinichiro/redirect_google.rb;
        }
    }

redirect_absolute.rb
Nginx.redirect "http://sample.com/index.html" , Nginx::HTTP_MOVED_TEMPORARILY
redirect_google.rb
Nginx.redirect "https://www.google.co.jp/?gws_rd=ssl" , Nginx::HTTP_MOVED_TEMPORARILY
redirect_local.rb
Nginx.redirect "/index.html" , Nginx::HTTP_MOVED_TEMPORARILY

問題

redirect_absolute.rbを経由して、ホストを指定せずにローカル内でリダイレクトした時にログが出力されない。
他の2パターンはログに出力される。
Nginx + mrubyのバグだろうか。

解決策

とりあえずやっつける。

redirect_local.rb
var        = Nginx::Var.new
req        = Nginx::Request.new
Nginx.redirect "http://" + var.host + "/index.html" , Nginx::HTTP_MOVED_TEMPORARILY
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1