Reputation: 1682
I just deployed a Rails app to Elastic Beanstalk, and every request is giving me a 502 error.
Here's the contents of /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
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?
Upvotes: 26
Views: 13835
Reputation: 23661
Check if you're missing any newly added ENV variables.
To add new Environment variables follow:
Elastic Beanstalk
>Environments
><Your Environment>
>Configuration
>Software
>EDIT
Under Environment properties
Add the new ENV variables
Upvotes: 0
Reputation: 147
Add a Procfile
with this content:
web: puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb
Reference:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ruby-platform-procfile.html
Upvotes: 3
Reputation: 1738
In my case, this was happening because of a Gem loading error. I was able to reproduce the error by connecting to the server with eb ssh
and running pumactl start
.
For me, the conflict was with the nio4r
gem, although for others it was the puma
gem. Setting it to the same version as the Elastic Beanstalk platform's gem fixed the error.
More details here: https://stackoverflow.com/a/67110462/1852005 and here: https://forums.aws.amazon.com/thread.jspa?messageID=957426
Upvotes: 4
Reputation: 65
Given you are using Elastic Beanstalk, it starts up puma
by running a command very similar to this one (as you can see by running ps
):
sudo su -s /bin/bash -c "puma -C /opt/elasticbeanstalk/support/conf/pumaconf.rb webapp"
Try running that command in your eb ssh console. If you get an error like the one in this post:
config/puma.rb:23:in `_load_from': undefined local variable or method `daemonize' for #<Puma::DSL:0x000055596fadb448> (NameError)
you have probably declared Puma 5.x in your Gemfile. The solution would be to use puma < 5.0, as it removed the daemonize
method. Note that the configuration Elastic Beanstalk uses is not config/puma.rb
but /opt/elasticbeanstalk/support/conf/pumaconf.rb
Upvotes: 0
Reputation: 351
The error unix:///var/run/puma/my_app.sock failed (2: No such file or directory)
will also occur if Elastic Beanstalk cannot detect your Rails application root for whatever reason. In my case, the issue was simply that I was zipping up my Rails application contents inside a subfolder. Instead of creating the zip in the same directory as app
, bin
, config
, db
, etc., the application content were being created inside a subfolder called <app_name>
.
The only hint was in the Elastic Beanstalk Events section where it had an Informational notification (not warning or error level) which said Gemfile not detected. Custom gems will not be included.
Hope this helps others; took many deployments to figure out this simple problem.
Upvotes: 0
Reputation: 396
Sorry - Super late to the game. But I found this entry when searching for the same error message and could solve it differently.
I am trying to let a Rails 6.1.1 (currently latest and greatest) application run on AWS Beanstalk (Puma with Ruby 2.6), where I got the same error as described in this post: Nginx throwing above connection error / Puma seems not reactive (no entries in puma logs) / When SSHing into the machine it shows Puma is running (initctl status puma
-> shows process ID).
After some days of research (and trying all above answers without success) - I switched to Passenger - but still same result. Researching the same problem for Passenger showed the proper solution:
Do not use the gem of the application server in production when you want to use the already provided application server of the AWS platform branch ("Puma with Ruby 2.6..." or "Passenger with Ruby 2.6...") (it somehow collides with the already installed version). Therefore in your Gemfile:
gem 'puma', '~> 5.0', groups: [:development, :test]
respectively:
gem "passenger", ">= 5.3.2", require: "phusion_passenger/rack_handler", groups: [:development, :test]
or use the AWS Beanstalk platform without already installed application server ("Ruby 2.6 running on...)
PS: Seems to be only a solution for higher Rails versions (my old Rails 5.1 app runs perfectly on the "Puma with Ruby 2.6" platform even with the gem "normally" installed.
Upvotes: 6
Reputation: 1298
Changing config.force_ssl = true
to false
fixed the issue for me.
Upvotes: 1
Reputation: 9491
I faced the same error and adding these two lines to config/puma.rb
fixed the problem:
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.
Hope this helps.
Upvotes: 22
Reputation: 13583
The AWS doc mandates that puma gem be installed as part of your application.
Add the following to your Gemfile as appropriate:
group :production do
gem 'puma'
end
Upvotes: 0
Reputation: 4386
This line in your logfile means, that you've configured your nginx incorrectly.
upstream: "http://unix:///var/run/puma/my_app.sock:/get"
Actually nginx tries to use unix domain socket as HTTP url.
Can't say exactly what is wrong at your nginx config without it, but you should have something like this:
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
Upvotes: 0