加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:28:50 所属栏目:Nginx 来源:网络整理
导读:按照一个应用程序点击部署.数据库做得很好,即使我检查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 ` 和nginx的错误是

按照一个应用程序点击部署.数据库做得很好,即使我检查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 `

和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 

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

kill -s QUIT $(< /var/run/unicorn.pid)
bundle exec unicorn -c 

然后重新启动nginx

sudo service nginx restart

看看它是否工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读