nginx_php.conf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. user www-data;
  2. worker_processes auto;
  3. error_log stderr error;
  4. #worker_rlimit_nofile 100000;
  5. #timer_resolution 1000ms;
  6. daemon off;
  7. events {
  8. worker_connections 65536;
  9. multi_accept off;
  10. }
  11. http {
  12. include /etc/nginx/mime.types;
  13. access_log off;
  14. server_tokens off;
  15. sendfile off;
  16. tcp_nopush off;
  17. tcp_nodelay on;
  18. keepalive_timeout 65s;
  19. keepalive_disable none;
  20. keepalive_requests 10000;
  21. php_ini_path /deploy/conf/php.ini;
  22. init_worker_by_php '
  23. define("DB_HOST", gethostbyname("tfb-database"));
  24. define("DB_PORT", "3306");
  25. define("DB_USER", "benchmarkdbuser");
  26. define("DB_PASS", "benchmarkdbpass");
  27. define("DB_NAME", "hello_world");
  28. ';
  29. server {
  30. listen 8080 default_server reuseport;
  31. root /;
  32. index index.html;
  33. php_keepalive 200;
  34. location = /hello {
  35. add_header Content-Type text/plain;
  36. content_by_php '
  37. echo "Hello, World!";
  38. ';
  39. }
  40. location = /json {
  41. add_header Content-Type application/json;
  42. content_by_php '
  43. echo json_encode(["message" => "Hello, World!"]);
  44. ';
  45. }
  46. location = /fortune {
  47. content_by_php '
  48. require_once("/ngx_php7/t/lib/mysql.php");
  49. ngx_header_set("Content-Type", "text/html; charset=UTF-8");
  50. $my = new php\\ngx\mysql();
  51. yield from $my->connect(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME);
  52. $ret = yield from $my->query("SELECT id, message FROM Fortune");
  53. $arr = [];
  54. foreach ($ret as $row) {
  55. $arr[$row["id"]] = $row["message"];
  56. }
  57. $arr[0] = "Additional fortune added at request time.";
  58. asort($arr);
  59. $html = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>\n";
  60. foreach ( $arr as $id => $fortune ) {
  61. $html.="<tr><td>{$id}</td><td>".htmlspecialchars($fortune, ENT_QUOTES, "UTF-8")."</td></tr>\n";
  62. }
  63. $html .= "</table></body></html>\n";
  64. echo $html;
  65. yield from $my->close();
  66. ';
  67. }
  68. location = /dbraw {
  69. add_header Content-Type application/json;
  70. content_by_php '
  71. include "dbraw.php";
  72. ';
  73. }
  74. location /dbquery {
  75. add_header Content-Type application/json;
  76. content_by_php '
  77. $_GET = ngx::query_args();
  78. include "dbquery.php";
  79. ';
  80. }
  81. location /update {
  82. add_header Content-Type application/json;
  83. content_by_php '
  84. $_GET = ngx::query_args();
  85. include "updateraw.php";
  86. ';
  87. }
  88. }
  89. }