I've got apache as a back-end server, which runs php scripts and nginx as a reverse-proxy server which deals with static content. A php-script, which gives me ID of some process and then performs this process (pretty long). I need to pass to browser only the ID of that proccess.
// ...
ob_start();
echo json_encode($arResult); // only this data should be passed to browser
$contentLength = ob_get_length();
header('Connection: close');
header('Content-Length: ' . $contentLength);
ob_end_flush();
ob_flush();
flush();
// then performed a long process
(I check the status of the proccess with another ajax-script)
This works fine under apache alone. But I have problems when apache is behind nginx. In this case I get response only when the proccess is completly finished.
nginx settings:
server {
#...
proxy_set_header Connection close;
proxy_pass_header Content-Length;
#...
}
But I still get Connection keep-alive in FireBug.
How can I get nginx to immediately give a response from apache?
Hope the question is clear.
Thanks.
In this case NGINX uses only the buffer configured by proxy_buffer_size to store the current part of a response. A common use of a reverse proxy is to provide load balancing. Learn how to improve power, performance, and focus on your apps with rapid deployment in the free Five Reasons to Choose a Software Load Balancer ebook.
The proxy_pass directive can also point to a named group of servers. In this case, requests are distributed among the servers in the group according to the specified method. By default, NGINX redefines two header fields in proxied requests, “Host” and “Connection”, and eliminates the header fields whose values are empty strings.
In this case, requests are distributed among the servers in the group according to the specified method. By default, NGINX redefines two header fields in proxied requests, “Host” and “Connection”, and eliminates the header fields whose values are empty strings. “Host” is set to the $proxy_host variable, and “Connection” is set to close.
Proxying is typically used to distribute the load among several servers, seamlessly show content from different websites, or pass requests for processing to application servers over protocols other than HTTP. Passing a Request to a Proxied Server
Have you tried proxy_buffering off in nginx? Not sure it will close the connection but at least the response will be transmited as is to the client. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With