hn
By:
hn

Nginx: upstream prematurely closed connection while reading response header from upstream

December 12, 2013 59.2k views
Hello, I followed tutorial(https://www.digitalocean.com/community/articles/how-to-install-rails-and-nginx-with-passenger-on-ubuntu) to set up my Rails App(nginx 1.4.4, passenger 4.0 and mysql) on DigitalOcean's 512MB RAM and 20GB Disk server. I got below error once I started Nginx and visit my App. -- I checked /opt/nginx/logs/error.log, which shows "1 upstream prematurely closed connection while reading response header from upstream" at the latest line. -- Is this a performance issue on DigitalOcean's 512MB RAM server? anyone know how to fix this? Thanks!
1 comment
10 Answers

It was the same for me in Rails 4, but I have added a SECRET_KEY_BASE in /confirg/secrets.yml

production:
  secret_key_base: # add yours here
That usually means that passenger is timing out. Try checking its error logs and see if you can find any pointers in there.
Hello,
I followed tutorial(https://www.digitalocean.com/community/articles/how-to-install-rails-and-nginx-with-passenger-on-ubuntu)
I got upstream timed out (110: Connection timed out) while reading response header from upstream in error.log file
@anilapu: Is there anything in passenger's error logs?
@Kamal Nasser,
Could you please tell how can i check passenger's error logs?
I've never used passenger. Go through the config file and look for error_log, log_file, log, log_path, or anything similar.
I am having the same issue. Followed the tutorial and now the errors logs say that:
$ cat access.log
186.194.192.62 - - [13/Jun/2014:10:58:14 -0400] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4"
186.194.192.62 - - [13/Jun/2014:10:58:16 -0400] "GET / HTTP/1.1" 502 537 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4"

$ cat error.log
2014/06/13 10:58:16 [error] 28602#0: *3 upstream prematurely closed connection while reading response header from upstream, client: 186.194.192.62, server: test.representantevirtual.com, request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.28581/generation-0/request:", host: "test.representantevirtual.com"
any ideas ?
  • Are you seeing any thing in the log for your Rails app? An error like that is generally going to be something on the Rails/Passenger side, not the Nginx side. You might possibly be running out of memory.

Hello,

i am running JIRA on Nginx, and hava the same error . does anyone fixed this?

2014/12/13 02:12:42 [error] 4198#0: *30 upstream prematurely closed connection while reading response header from upstream, client: xx.xx.xx.xx, server: www.jira.xxxx.com, request: "GET /s/d8$
2014/12/13 02:12:48 [error] 4198#0: *30 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: www.jira.xxxx.com, request: "GET /login.jsp?os_de$

just restart php-fpm, it worked for me!

Hello here, I have some issues:

2015/06/01 18:48:07 [error] 82618#0: *5006 upstream prematurely closed connection while reading response header from upstream, client: 141.101.104.74, server: http://linux-notes.org, request: "POST /xmlrpc.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "http://linux-notes.org"
2015/06/01 18:48:08 [error] 82618#0: *5014 upstream prematurely closed connection while reading response header from upstream, client: 141.101.104.74, server: http://linux-notes.org, request: "POST /xmlrpc.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "http://linux-notes.org"
2015/06/01 18:48:11 [error] 82616#0: *4388 upstream prematurely closed connection while reading response header from upstream, client: 141.101.104.74, server: http://linux-notes.org, request: "POST /xmlrpc.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "http://linux-notes.org"

Kindly, help me. I rebooted the php-fpm and nginx and it's not solve me issue :(
Thanks.

Have another answer? Share your knowledge.