ruby-on-rails - Nginx/ unicorn : Upstream timed out (110: Connection timed out) while reading response header from upstream

标签 ruby-on-rails http nginx amazon-ec2 unicorn

我的 rails nginx/unicorn 服务器出现上游超时错误。我已尝试解决此问题,但没有找到适合我的解决方案。

我正在粘贴我在 nginx error.log 文件中得到的确切错误:

 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"

我正在关注以下 2 篇关于在我的 ubuntu EC2 机器上使用 Ruby on Rails 应用程序设置 nginx 和 unicorn 的博客:

  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

我能够在端口 3000 上的生产环境中运行服务器,但现在,我需要在端口 80 上运行服务器,以便我可以将 DNS 指向我的服务器 IP。我使用了以下方法来运行它:

  • 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.

请检查我已经尝试过的所有上述内容,如果我缺少任何在端口 80 上使用 nginx/unicorn 运行服务器的内容,请告诉我。


/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;
}

最佳答案

我遇到了同样的问题。为了修复它,我检查了/var/log/unicorn/unicorn.log 文件,发现 imagemagick 丢失了。

在 Ubuntu 上修复它:

sudo apt-get install imagemagick

关于ruby-on-rails - Nginx/ unicorn : Upstream timed out (110: Connection timed out) while reading response header from upstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31277652/

相关文章:

sql - PostgreSQL:选择一周中某一天、特定时区发生的行

json - Powershell Invoke-RestMethod 响应不完整

http - 重写重定向以包括用于访问服务的端口

php - 一个php容器上具有两个单独的php-services的docker

regex - 获取url参数并保存变量或cookie

sql - ruby on rails update_attributes 是否可以防止 sql 注入(inject)?

ruby-on-rails - remove_reference 和 add_reference 的向下迁移报告没有外键

javascript - Ruby on Rails 实时更新

http - 这里应该使用 401 Unauthorized 还是 403 Forbidden?

python - 在不下载正文的情况下检查 Python 中的 HTTP POST header