c++ - nginx / FastCGI application loads page multiple times per request -
i following this tutorial, , modified code , added counter it. page displays "hello world" , displays counter. now, weird thing is, code compiles fine, count goes 2 each time refresh page!
i'm spawning process this: spawnfcgi.exe -a 127.0.0.1 -p 8000 -f myapp.exe
everything loads ok, again, count jumps 0 2 4 etc. each time refresh page. if write line file, same line written multiple times, increasing each time load webpage. question is, intended effect of fastcgi application? or there kind of bug in code and/or fastcgi/nginx config?
main.cpp (hello world)
#include <iostream> #include "fcgio.h" using namespace std; int main(void) { int gcount = 0; // backup stdio streambufs streambuf * cin_streambuf = cin.rdbuf(); streambuf * cout_streambuf = cout.rdbuf(); streambuf * cerr_streambuf = cerr.rdbuf(); fcgx_request request; fcgx_init(); fcgx_initrequest(&request, 0, 0); while (fcgx_accept_r(&request) == 0) { fcgi_streambuf cin_fcgi_streambuf(request.in); fcgi_streambuf cout_fcgi_streambuf(request.out); fcgi_streambuf cerr_fcgi_streambuf(request.err); cin.rdbuf(&cin_fcgi_streambuf); cout.rdbuf(&cout_fcgi_streambuf); cerr.rdbuf(&cerr_fcgi_streambuf); cout << "content-type: text/html\r\n" << "\r\n" << "<html>\n" << " <head>\n" << " <title>hello, world!</title>\n" << " </head>\n" << " <body>\n" << " <h1>hello, world!</h1>\n" << gcount++ << " </body>\n" << "</html>\n"; // note: fcgi_streambuf destructor auto flush } // restore stdio streambufs cin.rdbuf(cin_streambuf); cout.rdbuf(cout_streambuf); cerr.rdbuf(cerr_streambuf); return 0; }
nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { server { listen 80; server_name localhost; location / { fastcgi_pass 127.0.0.1:8000; fastcgi_param gateway_interface cgi/1.1; fastcgi_param server_software nginx; fastcgi_param query_string $query_string; fastcgi_param request_method $request_method; fastcgi_param content_type $content_type; fastcgi_param content_length $content_length; fastcgi_param script_filename $document_root$fastcgi_script_name; fastcgi_param script_name $fastcgi_script_name; fastcgi_param request_uri $request_uri; fastcgi_param document_uri $document_uri; fastcgi_param document_root $document_root; fastcgi_param server_protocol $server_protocol; fastcgi_param remote_addr $remote_addr; fastcgi_param remote_port $remote_port; fastcgi_param server_addr $server_addr; fastcgi_param server_port $server_port; fastcgi_param server_name $server_name; } } }
fastcgi.conf
#fastcgi.conf fastcgi_param gateway_interface cgi/1.1; fastcgi_param server_software nginx; fastcgi_param query_string $query_string; fastcgi_param request_method $request_method; fastcgi_param content_type $content_type; fastcgi_param content_length $content_length; fastcgi_param script_filename $document_root$fastcgi_script_name; fastcgi_param script_name $fastcgi_script_name; fastcgi_param request_uri $request_uri; fastcgi_param document_uri $document_uri; fastcgi_param document_root $document_root; fastcgi_param server_protocol $server_protocol; fastcgi_param remote_addr $remote_addr; fastcgi_param remote_port $remote_port; fastcgi_param server_addr $server_addr; fastcgi_param server_port $server_port; fastcgi_param server_name $server_name;
can show nginx.conf ?
and browser chrome or chronium?
Comments
Post a Comment