使用Puma部署在Elastic Beanstalk上的Rails应用程序失败 - 每个请求都有502个错误

[英]Rails application deployed on Elastic Beanstalk with Puma fails - 502 errors on every request


I just deployed a Rails app to Elastic Beanstalk, and every request is giving me a 502 error.

我刚刚将一个Rails应用程序部署到Elastic Beanstalk,每个请求都给我一个502错误。

Here's the contents of /var/logs/nginx/error.log

这是/var/logs/nginx/error.log的内容

2015/05/20 16:24:25 [warn] 1535#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2015/05/20 16:27:12 [crit] 1537#0: *20 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:27:17 [crit] 1537#0: *20 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:27:19 [crit] 1537#0: *20 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:27:22 [crit] 1537#0: *16 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.44.210, server: _, request: "GET /datapoint?tickers=AAPL&datapoints=Ratings HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/datapoint?tickers=AAPL&datapoints=Ratings", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:27:27 [crit] 1537#0: *20 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:27:32 [crit] 1537#0: *20 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:28:53 [crit] 1537#0: *52 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "GET /datapoint?tickers=AAPL&datapoints=Ratings HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/datapoint?tickers=AAPL&datapoints=Ratings", host: "securities-api-prod.elasticbeanstalk.com"
2015/05/20 16:30:47 [crit] 1537#0: *69 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.51.94, server: _, request: "POST /get HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/get", host: "securities-api-prod.elasticbeanstalk.com"

I think puma is running -

我觉得彪马正在运行 -

[ec2-user@ip-172-31-44-135 nginx]$ ps aux | grep puma
root     23299  1.0  0.2  53008  1428 ?        Ss   16:38   0:00 su -s /bin/bash -c puma -C /opt/elasticbeanstalk/support/conf/pumaconf.rb webapp
webapp   23314  0.0  2.4  75764 14604 ?        Rsl  16:38   0:00 /opt/rubies/ruby-2.1.4/bin/ruby /opt/rubies/ruby-2.1.4/bin/puma -C /opt/elasticbeanstalk/support/conf/pumaconf.rb
ec2-user 23317  0.0  0.1 110284   844 pts/0    S+   16:38   0:00 grep puma

pumaconf.rb

pumaconf.rb

directory '/var/app/current'
threads 8, 32
workers %x(grep -c processor /proc/cpuinfo)
bind 'unix:///var/run/puma/my_app.sock'
stdout_redirect '/var/log/puma/puma.log', '/var/log/puma/puma.log', true
daemonize false

Anyone know what's going on?

有谁知道发生了什么事?

4 个解决方案

#1


12  

I faced the same error and adding these two lines to config/puma.rb fixed the problem:

我遇到了同样的错误,并将这两行添加到config / puma.rb修复了问题:

bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"

After this step I faced another error to add ENV values, which is very straight forward.

在这一步之后,我面临另一个错误,即添加ENV值,这非常简单。

Hope this helps.

希望这可以帮助。

#2


0  

This line in your logfile means, that you've configured your nginx incorrectly.

日志文件中的这一行表示您已经错误地配置了nginx。

upstream: "http://unix:///var/run/puma/my_app.sock:/get"

Actually nginx tries to use unix domain socket as HTTP url.

实际上nginx尝试使用unix域套接字作为HTTP url。

Can't say exactly what is wrong at your nginx config without it, but you should have something like this:

如果没有它,你不能确切地说你的nginx配置有什么问题,但是你应该有这样的东西:

upstream backend {
  server backend1.example.com weight=5;
  server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;
  server unix:/tmp/backend3;

  server backup1.example.com  backup; 
}

You should also check out this nginx doc http://nginx.org/en/docs/http/ngx_http_upstream_module.html

你还应该查看这个nginx doc http://nginx.org/en/docs/http/ngx_http_upstream_module.html

#3


0  

The AWS doc mandates that puma gem be installed as part of your application.

AWS文档要求将puma gem作为应用程序的一部分进行安装。

Add the following to your Gemfile as appropriate:

根据需要将以下内容添加到Gemfile:

group :production do
  gem 'puma'
end

#4


0  

Changing config.force_ssl = true to false fixed the issue for me.

将config.force_ssl = true更改为false可以解决我的问题。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/05/20/37e3722b18054919274ef012276a374d.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号