Skip to content

Instantly share code, notes, and snippets.

@hiboma
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save hiboma/b63d23802206cf2b983c to your computer and use it in GitHub Desktop.

Select an option

Save hiboma/b63d23802206cf2b983c to your computer and use it in GitHub Desktop.

要件

  • proxy する前に ngx_mruby で認証したい

mruby_access_handler_code の検証に書いた nginx.conf

  • ngx_mruby は master を clone
  • nginx は nginx/1.7.6
worker_processes  1;
daemon off;
error_log  /dev/stderr debug;

events {
    worker_connections  1024;
}

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /dev/stdout main;

    server {
        listen       10000;
        server_name  localhost;

        location / {
            mruby_access_handler_code 'Nginx.return Nginx::HTTP_OK';

            # 他に試したコード 
            # mruby_rewrite_handler_code 'Nginx.return Nginx::HTTP_OK';
            # mruby_server_rewrite_handler_code 'Nginx.return Nginx::HTTP_OK';
            # mruby_post_read_handler_code 'Nginx.return Nginx::HTTP_OK';
            proxy_pass http://lolipop.jp;
        }
    }
}

結果

500 を返してしまったのでした

$ curl http://localhost:10000/proxy
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx/1.7.6</center>
</body>
</html>

エラーログを貼っておきます

$ ./sbin/nginx 
2014/10/10 15:19:59 [notice] 73539#0: using the "kqueue" event method
2014/10/10 15:19:59 [warn] 73539#0: 1024 worker_connections exceed open file resource limit: 256
nginx: [warn] 1024 worker_connections exceed open file resource limit: 256
2014/10/10 15:19:59 [notice] 73539#0: nginx/1.7.6
2014/10/10 15:19:59 [notice] 73539#0: built by clang 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
2014/10/10 15:19:59 [notice] 73539#0: OS: Darwin 13.2.0
2014/10/10 15:19:59 [notice] 73539#0: hw.ncpu: 4
2014/10/10 15:19:59 [notice] 73539#0: net.inet.tcp.sendspace: 131072
2014/10/10 15:19:59 [notice] 73539#0: kern.ipc.somaxconn: 128
2014/10/10 15:19:59 [notice] 73539#0: getrlimit(RLIMIT_NOFILE): 256:9223372036854775807
2014/10/10 15:19:59 [notice] 73539#0: start worker processes
2014/10/10 15:19:59 [notice] 73539#0: start worker process 73540
2014/10/10 15:20:01 [error] 73540#0: *1 ngx_mruby ERROR ngx_mrb_send_header: status code is 200, but response body is empty.Return NGX_HTTP_INTERNAL_SERVER_ERROR, client: 127.0.0.1, server: localhost, request: "GET /proxy HTTP/1.1", host: "localhost:10000"
2014/10/10 15:20:01 [info] 73540#0: *1 ngx_mruby INFO ngx_mrb_run:696: mrb_run info: rputs_chain is null and return NGX_OK, client: 127.0.0.1, server: localhost, request: "GET /proxy HTTP/1.1", host: "localhost:10000"
127.0.0.1 - - [10/Oct/2014:15:20:01 +0900] "GET /proxy HTTP/1.1" 500 192 "-" "curl/7.30.0" "-"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment