簡體   English   中英

Nginx / Unicorn:上游超時(110:連接超時),同時從上游讀取響應頭

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

我在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和獨角獸:

  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上運行應用程序后,將創建unicorn -c config/unicorn.rb -E production - unicorn -c config/unicorn.rb -E production

  • 在可用/默認站點中,所有配置都正確,包括上游。

  • 在啟用站點/默認站點中,配置與可用站點/默認站點相同,因為這兩個站點都是鏈接的。 該文件包含在/ etc / nginx /目錄下的nginx.conf文件中。

  • 在日志中,我收到上游超時錯誤。 這也表明nginx需要花一些時間連接到unicorn.todo.socket,但由於所有配置正確並且在其他服務器上正確地運行相同的東西,因此無法調試此部分。

  • 我已經使用'sudo nginx -t'命令檢查了nginx的配置,這也表明一切正常。

  • 超時后,我在公用文件夾中收到ruby 500頁面的錯誤,這意味着路徑和其他配置也正確。

  • 我已經完全刪除了nginx和相關組件,然后將它們重新安裝到服務器上,但是再沒有成功。

  • 當我運行sudo service nginx restart ,它將重新啟動nginx,我可以看到nginx服務器運行了一些pid。

  • 我已經更改了unicorn.rb監聽路徑的路徑,這也無法正常工作。

  • 我用於此服務器的獨角獸版本正在另一台服務器上工作,因此我沒有更改。

  • 添加了proxy_read_timeout 150但這也無法正常工作。

請檢查我已經嘗試過的所有上述操作,如果我缺少使用端口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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM