Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stream init and exit directives with mruby, and access control methods #141

Merged
merged 13 commits into from Nov 3, 2015

Conversation

@matsumotory
Copy link
Owner

commented Nov 2, 2015

  • shared mruby state between init and session phase
  • add init directive
  • add worker init directive
  • add worker exit directive
  • support mruby internal context like stream status or stream_sessiont
  • add the control methods for nginx stream status

example

  • nginx.conf
stream {
  upstream dynamic_server0 {
    server 127.0.0.1:58080;
  }
  upstream dynamic_server1 {
    server 127.0.0.1:58081;
  }

  mruby_stream_init_code '
    Userdata.new.new_upstream = "127.0.0.1:58081"
  ';

  mruby_stream_init_worker_code '
    p "ngx_mruby: STREAM: mruby_stream_init_worker_code"
  ';

  mruby_stream_exit_worker_code '
    p "ngx_mruby: STREAM: mruby_stream_exit_worker_code"
  ';

  server {
    listen 12346;
    mruby_stream_code '
      # get from mruby_stream_init
      Nginx::Stream::Connection.new("dynamic_server0").upstream_server = Userdata.new.new_upstream
    ';
    proxy_pass dynamic_server0;
  }

  server {
    listen 12345;
    # code cached only
    mruby_stream build/nginx/html/stream_lb.rb;
    proxy_pass dynamic_server1;
  }

  server {
    listen 12347;
    mruby_stream_code '
      if Nginx::Stream::Connection.remote_ip == "127.0.0.1"
        current_status = Nginx::Stream::Connection.stream_status
        Nginx::Stream::Connection.stream_status = Nginx::Stream::ABORT
        Nginx::Stream.log Nginx::Stream::LOG_NOTICE, "current status=#{(current_status == Nginx::Stream::DECLINED) ? "NGX_DECLINED" : current_status} but deny from #{Nginx::Stream::Connection.remote_ip} return NGX_ABORT"
      end
    ';
    proxy_pass dynamic_server1;
  }
}
  • build/nginx/html/stream_lb.rb
c = Nginx::Stream::Connection.new "dynamic_server1"
c.upstream_server = "127.0.0.1:58080"

@matsumotory matsumotory changed the title [WIP] Support stream init func with mruby Support stream init func with mruby Nov 3, 2015

@matsumotory matsumotory changed the title Support stream init func with mruby Support stream init and exit directives with mruby, and access control methods Nov 3, 2015

matsumotory added a commit that referenced this pull request Nov 3, 2015
Merge pull request #141 from matsumoto-r/support-stream-init
Support stream init and exit directives with mruby, and access control methods

@matsumotory matsumotory merged commit 91e134d into master Nov 3, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.