简体   繁体   中英

Nginx/Unicorn: Upstream timed out (110: Connection timed out) while reading response header from upstream

I am getting upstream timeout error in my rails nginx/unicorn server. I have tried to fix this but did not find any solution that can work for me.

I am pasting the exact error which I am getting in nginx error.log file:

 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: default_server, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.todo.socket/", host: "xxx.xxx.xxx.xxx"

I am following below 2 blogs for setting up nginx and unicorn with Ruby on Rails app in my ubuntu EC2 machine:

  1. https://gist.github.com/billie66/3696537
  2. https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04

I am able to run the server in production environment on port 3000 but now, I am in need to run the server on port 80 so that I can point DNS to my server IP. I have used following methods to make this running:

  • unicorn.todo.socket is there which was being created after running application on unicorn using this command - unicorn -c config/unicorn.rb -E production

  • In sites-available/default, all the configurations are right including upstream.

  • In sites-enabled/default, configuration is same as sites-available/default as these both are linked. This file is included in nginx.conf file inside the /etc/nginx/ directory.

  • In log, I am getting error of upstream timeout. This was also showing that nginx taking time to connect to unicorn.todo.socket but could not debug this part as all configuration were right and running the same thing on some other server properly.

  • I have checked using 'sudo nginx -t' command for nginx configuration and this was also showing everything is OK.

  • After timeout, I am getting error of ruby 500 page in public folder, it means path and other configuration are also right.

  • I have completely removed the nginx and related component and re-installed those to server again, but no success again.

  • When I run sudo service nginx restart , it restarts the nginx and I can see the nginx server running with some pid.

  • I have changed the path for unicorn.rb listen path and this also not working.

  • The unicorn version I am using for this server, is working on another server so I did not change this.

  • Added proxy_read_timeout 150 but this is also not working.

Please check all the above things which I have already tried and let me know if I am missing anything to run the server using nginx/unicorn on port 80.


/etc/nginx/sites-enabled/default

upstream app {
  server unix:/tmp/unicorn.todo.socket fail_timeout=0;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name default_server;
  root /home/ubuntu/<project_folder>/public;

  try_files $uri/index.html $uri @app;

  location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app;
      proxy_read_timeout 150;
  }
  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

I faced the same issue. In order to fix it I checked /var/log/unicorn/unicorn.log file and found that imagemagick was missing.

To fix it on Ubuntu:

sudo apt-get install imagemagick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM