Upstream prematurely closed connection while reading response header from upstream

by Việt Nam Tutor
0 comment 3 mins read

This problem happened because your upstream (php, php-fpm) max_execution_time is shorter than proxy_connect_timeout in your nginx proxy.

For example:

In my php.ini:

max_execution_time = 30

But in mysite.conf have:

location / {
     proxy_set_header        Host $server_name;
     proxy_set_header        X-Real-IP $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header        X-Forwarded-Proto $scheme;
     proxy_pass http://localhost:8080;
     proxy_read_timeout 300; 
     proxy_connect_timeout 300;  # <== this
     proxy_request_buffering off;
     proxy_buffering off;
     proxy_redirect off;
 }

Then I got in error.log of nginx:

[error] 117#117: *434 upstream prematurely closed connection while sending to client….

To resolve this problem, increase your max_execution_time to 300.

That all!

Additional info: https://stackoverflow.com/questions/49508218/upstream-prematurely-closed-connection-while-reading-response-header-from-upstre

You may also like

Leave a Comment