This post consists of: http://xinpure.com/nginx-error-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/
Environment description
Nginx version 1.10.2
PHP version 7.0.12
Node version 5.9.0
This article is to tell a Nginx error, why also mention the PHP and Node version? Let me first restore the application scenario
First, I have a Node Server that's bound to Port 3000.
I need to access this service directly from port 80, so I used the Nginx reverse proxy
And as for PHP, in fact, this error is related to it
Find the cause of the error
When I used this Node Server, I returned a 502 bad Gateway error.
See the network request, there is no error, and then look at the error message in Nginx error log
[error] 17028#0: *111 upstream prematurely closed connection while reading response header from upstream
Well, it's not an obvious error, but to Google check.
It seems that a lot of people have encountered this problem, but the solution to the problem seems to be different.
Some say is keepalive_timeout value is too small (this value I according to the service configuration, has changed to 600, feel unlikely), and said restart Nginx on the line (tried. ), etc...
Of course there is a bright answer to my eyes, that is to restart the PHP-FPM, a decisive attempt
Sure enough ... Start error, the hint is probably meant that the port is occupied, the moment feels like looking for the right breach
Resolve Errors
Looked at the port only to find that the original is already opened another Node Server occupies the PHP-FPM default 9000 port
It's a pit of my own!
Because the service port can not be changed, and other colleagues to unify, so I changed the PHP-FPM port to 9999
PHP is installed using brew, the configuration path is:/usr/local/etc/php/7.0/php-fpm.d/www.conf
listen = 127.0.0.1:9999
And then restart the PHP-FPM and it's OK.
Nginx error:upstream prematurely closed connection while reading response headers from upstream