2015-05-20 42 views
11

我剛剛部署了一個Rails應用程序到Elastic Beanstalk,並且每個請求都給我一個502錯誤。使用Puma部署在Elastic Beanstalk上的Rails應用程序失敗 - 每次請求都會出現502錯誤

這裏的/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" 

我認爲彪馬運行 -

[[email protected] 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 

任何人都知道這是怎麼回事?

+0

請提供您的pumaconf.rb 看來,nginx尋找有代表性的彪馬套接字文件 –

+0

@StanislavMekhonoshin添加! – chintanparikh

+0

我遇到類似的問題。你找到解決辦法嗎? – Disha

回答

0

你的日誌文件中的這一行意味着你錯誤地配置了你的nginx。

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

其實nginx嘗試使用unix域套接字作爲HTTP url。

不能說什麼是錯的,沒有它你的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; 
} 

你也應該看看這個nginx的文檔http://nginx.org/en/docs/http/ngx_http_upstream_module.html

+1

nginx配置所在的任何想法? – chintanparikh

+0

我沒有EBS的經驗,但通常nginx配置位於/ etc/nginx/sites-enabled/* 但是我試着改變'bind'unix:/// var/run/puma /例如,my_app.sock'到'bind'tcp://0.0.0.0:8080''。這將是更容易 –

0

的AWS文檔要求將美洲獅寶石安裝爲應用程序的一部分。

以下添加到您的Gemfile酌情:

group :production do 
    gem 'puma' 
end 
+0

我仍然得到[錯誤](http://stackoverflow.com/questions/37472304/rails-elastic-beanstalk-connection-time-out-puma-server)。似乎請求首先在時間戳之前前往nginx。不知道如何解決這個問題 –

6

我面臨同樣的錯誤,並添加以下兩行config/puma.rb解決了這一問題:

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

這一步我面臨的另一個錯誤後添加ENV值,這是非常簡單的。

希望這會有所幫助。

相關問題