【发布时间】:2014-05-05 23:24:57
【问题描述】:
我有一个配置好的 nginx 站点在我运行时启用/可用:
nginx -t
我通过了成功的测试,当我:
service nginx restart
thin restart -s 1
我的 502 错误消失了,但仅持续了 10 秒钟,然后又出现了。我的可用网站是:
upstream myapp {
server 0.0.0.0:3000;
}
服务器{ 听 80 默认;
access_log /webservices/crawler/log/access.log;
error_log /webservices/crawler/error.log;
root /webservices/crawler/public/;
index index.html;
client_max_body_size 500M;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html;
break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html;
break;
}
if (!-f $request_filename) {
proxy_pass http://myapp;
break;
}
}
}
有人知道为什么我的配置只能运行几秒钟吗?感谢您的帮助,如果您需要查看我的任何其他代码,请告诉我。
thin restart -s 2 输出:
/# thin restart -s 2
Stopping server on 0.0.0.0:3000 ...
/usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:131:in `send_signal': Can't stop process, no PID found in tmp/pids/thin.3000.pid (Thin::PidFileNotFound)
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:113:in `kill'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:93:in `block in stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:134:in `tail_log'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:92:in `stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:187:in `run_command'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:152:in `run!'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/bin/thin:6:in `<top (required)>'
from /usr/local/bin/thin:23:in `load'
from /usr/local/bin/thin:23:in `<main>'
Stopping server on 0.0.0.0:3001 ...
/usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:131:in `send_signal': Can't stop process, no PID found in tmp/pids/thin.3001.pid (Thin::PidFileNotFound)
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:113:in `kill'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:93:in `block in stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:134:in `tail_log'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:92:in `stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:187:in `run_command'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:152:in `run!'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/bin/thin:6:in `<top (required)>'
from /usr/local/bin/thin:23:in `load'
from /usr/local/bin/thin:23:in `<main>'
Starting server on 0.0.0.0:3000 ...
Starting server on 0.0.0.0:3001 ...
我很确定这是一个瘦问题,而不是 nginx 问题,所以我发布了一个更新。如有任何混淆,请见谅。
我的网站启动了大约 10 秒,然后我收到 502 nginx 错误。我的 nginx 配置似乎很好,并且 nginx -t 成功。我的错误信息是这样的:
瘦重启-s 5
/usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:131:in send_signal': Can't stop process, no PID found in tmp/pids/thin.3004.pid (Thin::PidFileNotFound)
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/daemonizing.rb:113:inkill'
来自 /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:93:in block in stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:134:intail_log'
来自 /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/controllers/controller.rb:92:in stop'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:187:inrun_command'
来自 /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/lib/thin/runner.rb:152:in run!'
from /usr/local/lib/ruby/gems/2.0.0/gems/thin-1.5.1/bin/thin:6:in'
来自 /usr/local/bin/thin:23:in load'
from /usr/local/bin/thin:23:in'
我已经检查了 PID,它们在那里。有谁知道这里发生了什么?谢谢你,我很感激任何建议。
【问题讨论】:
-
这是我的 nginx -t 的实际输出: nginx: 配置文件 /etc/nginx/nginx.conf 语法没问题 nginx: 配置文件 /etc/nginx/nginx.conf 测试成功
-
502 表示您的应用服务器出现故障(崩溃)或不接受连接。
-
出现错误时是否正在运行瘦?当thin 由于内存不足或监视进程而关闭时,我会看到此错误。 (您最好也询问服务器故障)
-
是的,我很确定 Thin 正在运行,我会在上面为您发布 Thin restart -s 2 输出。
-
有点离题,但在 nginx 配置中使用
if通常是个坏主意。阅读wiki.nginx.org/Pitfalls#Check_IF_File_Exists。这可能看起来像gist.github.com/alexeyten/ca3af91fa06e1536df26
标签: ruby-on-rails nginx