ruby-on-rails – 504网关超时nginx / 1.4.6(Ubuntu)

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 504网关超时nginx / 1.4.6(Ubuntu)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
按照一个应用程序点击部署.数据库做得很好,即使我检查rails控制台一切正常.

Ruby版本是2.3.0,rails版本是5.0.1

但是当我打IP地址时,会出错

在检查独角兽日志我得到

/usr/local/rvm/gems/ruby-2.2.1/gems/unicorn-5.0.1/bin/unicorn:126:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `load'
/usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `<main>'
/usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `<main>'
E,[2017-02-26T15:47:18.969274 #9861] ERROR -- : reaped #<Process::Status: pid 11928 exit 1> worker=2
I,[2017-02-26T15:47:18.969471 #9861]  INFO -- : worker=2 spawning...
I,[2017-02-26T15:47:18.974112 #11942]  INFO -- : worker=2 spawned pid=11942
I,[2017-02-26T15:47:18.978540 #11936]  INFO -- : Refreshing Gem list
I,[2017-02-26T15:47:18.986558 #11938]  INFO -- : Refreshing Gem list

Nginx错误

017/02/26 15:34:17 [error] 18564#0: *31 connect() to unix:/var/run/unicorn.sock Failed (111: Connection refused) while connecting to upstream,client: 121.52.156.57,server: _,request: "GET / HTTP/1.1",upstream: "http://unix:/var/run/unicorn.sock:/",host: "188.166.157.124"
2017/02/26 15:35:42 [error] 32360#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream,client: 119.155.34.115,upstream: "http://unix:/var/run/unicorn.sock/",host: "188.166.157.124"
2017/02/26 15:42:38 [error] 6296#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream,client: 119.152.140.90,host: "188.166.157.124"

unicorn.conf

listen "unix:/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/company_startup"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"

ps aux | grep unicor

rails     4751 18.0  4.2 172880 21516 ?        R    14:59   0:00 unicorn worker[2] -D -c /etc/unicorn.conf -E production                                                                                              
rails     4757  0.0  4.1 172404 20972 ?        Rl   14:59   0:00 unicorn worker[3] -D -c /etc/unicorn.conf -E production                                                                                              
rails     4760  0.0  2.9 159860 14568 ?        Rl   14:59   0:00 unicorn worker[1] -D -c /etc/unicorn.conf -E production                                                                                              
root      4764  0.0  0.1  11712   620 pts/0    S+   14:59   0:00 grep --color=auto unicorn
root     20463  0.4  2.6 146740 13176 ?        Sl   04:32   2:48 unicorn master -D -c /etc/unicorn.conf -E production

Nginx文件在这里:

upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;

}

server {
listen   80;
root /home/rails/company_startup/public;
server_name _;
index index.htm index.html;
client_max_body_size 1M;
location / {
        try_files $uri/index.html $uri.html $uri @app;
}

location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)${
                try_files $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_server;
}
}

解决方法

这听起来像是独角兽重启问题.你说你不用capistrano.如何部署应用程序?

编辑

独角兽利用多进程架构更好地利用可用的资源.工作开始时,工作人员加载ruby环境,然后产生处理请求的工作人员.主人永远不会处理这个请求,总是工人.

当工作人员花费的时间太长时,主人可以杀死它并重新开始新的工人.

你似乎使用4名工人.我不知道你的水滴在DO上的大小,但似乎主人不能再开始工作了.你能告诉我你的液滴的大小(cpu和内存)吗?

我将安装unicorn-worker-killer gem并再次测试应用程序.这应该以比独角兽大师更有效的方式重新启动你的工人.

编辑2:
如果这不起作用,您可以尝试在Nginx conf文件中替换上游行:

upstream app_server { server 127.0.0.1:8080  fail_timeout=0; }

这在你的独角兽conf文件中:

listen "127.0.0.1:8080

然后重新启动Nginx然后独角兽.

编辑3:

我想我得到了

请你改变你的文件

unicorn.conf

listen "/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/company_startup"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"

Nginx文件

upstream app_server {
  server unix:/var/run/unicorn.sock fail_timeout=0;
}

server {
  listen   80;
  root /home/rails/company_startup/public;
  server_name <PLEASE PUT YOUR SERVER NAME>;
  index index.htm index.html;
  client_max_body_size 1M;

  location / {
    try_files $uri/index.html $uri.html $uri @app;
  }

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)${
    try_files $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_server;
  }
}

重新启动独角兽(请确保替换<>)之间的值

kill -s QUIT $(< /var/run/unicorn.pid)
bundle exec unicorn -c <PATH TO unicorn.conf FILE> -E <RAILS ENVIRONMENT> -D

然后重新启动Nginx

sudo service Nginx restart

看看它是否工作.

原文链接:/ruby/266561.html

猜你在找的Ruby相关文章