gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:35:48 29 4
gpt4 key购买 nike

按照 Rails 一键部署应用程序。数据库做得很好,即使我检查 rails 控制台一切正常。

Ruby 版本为 2.3.0,rails 版本为 5.0.1

但是当我点击 IP 地址时,它会出现错误超时

在检查 unicorn 日志时我得到

/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, server: _, request: "GET / HTTP/1.1", 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, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"

unicorn 配置文件
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辅助| grep unicorn
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;
}
}

最佳答案

这听起来像是 unicorn 重启问题。你说你不使用capistrano。你如何部署你的应用程序?

编辑

Unicorn 使用多进程架构更好地利用您可用的资源。当它启动时,worker 加载 ruby​​ 环境,然后产生处理请求的 worker。主人从不处理请求,总是 worker 。

当一个worker耗时过长时,master可以杀死它并重新启动一个新的worker。

您似乎使用了 4 个 worker 。我不知道你在 DO 上的 droplet 的大小,但似乎 master 不能再启动 worker。你能告诉我你的 Droplet 的大小(CPU 和内存)吗?

我会安装 unicorn-worker-killer gem并再次测试应用程序。这应该以比 unicorn 主人更有效的方式重新启动您的 worker 。

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

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

这在你的 unicorn conf 文件中:
listen "127.0.0.1:8080

并重新启动 nginx 然后 unicorn。

编辑 3:

我想我明白了

你能不能像这样改变你的文件:

unicorn 配置文件
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;
}
}

重启 unicorn (确保替换<>之间的值)
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-on-rails - 504 网关超时 nginx/1.4.6 (Ubuntu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42474119/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com