nginx.conf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pid /tmp/nginx.pid;
  2. #error_log stderr error;
  3. events {
  4. worker_connections 16384;
  5. }
  6. http {
  7. resolver 127.0.0.1;
  8. #access_log off;
  9. # https://github.com/matsumoto-r/ngx_mruby/wiki/Class-and-Method#nginxrequest-class
  10. # db connection pool
  11. mruby_init_worker_code 'Userdata.new("my_#{Process.pid}").db = MySQL::Database.new("DBHOSTNAME", "root", "", "benchmark")';
  12. mruby_exit_worker_code 'db = Userdata.new("my_#{Process.pid}").db ; db.close if db';
  13. server {
  14. listen 8000;
  15. server_name localhost;
  16. location / {
  17. root html;
  18. index index.html index.htm;
  19. }
  20. location /plaintext {
  21. default_type "text/plain";
  22. mruby_content_handler_code 'Nginx.rputs "Hello World!"';
  23. }
  24. location /json {
  25. default_type "application/json";
  26. mruby_content_handler_code 'Nginx.rputs JSON::stringify("message" => "Hello World!")';
  27. }
  28. location ~ /db {
  29. default_type "application/json";
  30. mruby_content_handler 'CWD/nginx_mruby/db.rb' cache;
  31. }
  32. location ~ /queries {
  33. default_type "application/json";
  34. mruby_content_handler 'CWD/nginx_mruby/queries.rb' cache;
  35. }
  36. location ~ /fotunes {
  37. default_type "application/html";
  38. mruby_content_handler 'CWD/nginx_mruby/fotunes.rb' cache;
  39. }
  40. #location ~ \.rb$ {
  41. # default_type "application/json";
  42. # mruby_add_handler on;
  43. #}
  44. #error_page 404 /404.html;
  45. error_page 500 502 503 504 /50x.html;
  46. location = /50x.html {
  47. root html;
  48. }
  49. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  50. #
  51. #location ~ \.php$ {
  52. # proxy_pass http://127.0.0.1;
  53. #}
  54. }
  55. }