123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- user www-data;
- worker_processes auto;
- error_log stderr error;
- #worker_rlimit_nofile 100000;
- #timer_resolution 1000ms;
- daemon off;
- events {
- worker_connections 65536;
- multi_accept off;
- }
- http {
- include /etc/nginx/mime.types;
- access_log off;
- server_tokens off;
- sendfile off;
- tcp_nopush off;
- tcp_nodelay on;
- keepalive_timeout 65s;
- keepalive_disable none;
- keepalive_requests 10000;
- php_ini_path /deploy/conf/php.ini;
- init_worker_by_php '
- define("DB_HOST", gethostbyname("tfb-database"));
- define("DB_PORT", "3306");
- define("DB_USER", "benchmarkdbuser");
- define("DB_PASS", "benchmarkdbpass");
- define("DB_NAME", "hello_world");
- ';
- server {
- listen 8080 default_server reuseport;
- root /;
- index index.html;
- php_keepalive 200;
- location = /hello {
- add_header Content-Type text/plain;
- content_by_php '
- echo "Hello, World!";
- ';
- }
- location = /json {
- add_header Content-Type application/json;
- content_by_php '
- echo json_encode(["message" => "Hello, World!"]);
- ';
- }
-
- location = /fortune {
- content_by_php '
- require_once("/ngx_php7/t/lib/mysql.php");
- ngx_header_set("Content-Type", "text/html; charset=UTF-8");
- $my = new php\\ngx\mysql();
- yield from $my->connect(DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME);
- $ret = yield from $my->query("SELECT id, message FROM Fortune");
-
- $arr = [];
- foreach ($ret as $row) {
- $arr[$row["id"]] = $row["message"];
- }
- $arr[0] = "Additional fortune added at request time.";
- asort($arr);
-
- $html = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>\n";
- foreach ( $arr as $id => $fortune ) {
- $html.="<tr><td>{$id}</td><td>".htmlspecialchars($fortune, ENT_QUOTES, "UTF-8")."</td></tr>\n";
- }
- $html .= "</table></body></html>\n";
- echo $html;
- yield from $my->close();
- ';
- }
- location = /dbraw {
- add_header Content-Type application/json;
- content_by_php '
- include "dbraw.php";
- ';
- }
- location /dbquery {
- add_header Content-Type application/json;
- content_by_php '
- $_GET = ngx::query_args();
- include "dbquery.php";
- ';
- }
- location /update {
- add_header Content-Type application/json;
- content_by_php '
- $_GET = ngx::query_args();
- include "updateraw.php";
- ';
- }
- }
- }
|