daemon off;
user daemon;
worker_processes auto;

events {
    worker_connections  1024;
}

env PROXY1_PORT_80_TCP_ADDR;
env PROXY1_PORT_80_TCP_PORT;
env PROXY2_PORT_80_TCP_ADDR;
env PROXY2_PORT_80_TCP_PORT;
env PROXY3_PORT_80_TCP_ADDR;
env PROXY3_PORT_80_TCP_PORT;

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /mruby-hello {
            mruby_content_handler_code 'Nginx.echo "server ip: #{Nginx::Connection.new.local_ip}: hello ngx_mruby world."';
        }

        location /mruby-test {
            mruby_content_handler /usr/local/nginx/hook/test.rb;
        }

        location /mruby-proxy {
            mruby_set $backend /usr/local/nginx/hook/proxy.rb;
            proxy_pass http://$backend;
        }

        # test for Nginx::Var
        # http://localhost/nginx_var?name=http_host
        location /nginx_var {
            mruby_content_handler_code '
              r = Nginx::Request.new
              Nginx.echo r.var.send r.var.arg_name.to_sym
              Nginx.return Nginx::HTTP_OK
            ';
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
