Rails app migrating to AWS Elastic Beanstalk :: Bad Gateway (502) - ruby-on-rails

So I'm migrating from Heroku to AWS Elastic Beanstalk and testing out the waters. I'm following this documentation:
AWS Docs :: Deploy Rails app to AWS
However after following the documentation I keep receiving a Bad Gateway 502 (error).
Here's the specs of my app:
Rails 4.1.8
Ruby 2.1.7
Server Puma
So I checked my /log/nginx/error.log and here is what I see:
2015/11/24 06:44:12 [crit] 2689#0: *4719 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.13.129, server: _, request: "G ET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "my-app-env-mympay5afd.elasticbeanstalk.com"
From this AWS Forum thread it appears as though Puma is not starting correctly.
So the three log files that I have taken a look at are:
/var/log/eb-activity.log
/var/log/eb-commandprocessor.log
/var/log/eb-version-deployment.log
and none of them seem to indicate any errors except for the "secret_key_base" error which I fixed (I used the eb setenv SECRET_KEY_BASE=[some_special_key] command).
One thing that could hint at the source of the issue is /var/log/nginx/rotated/error.log1448330461.gz has the following content
2015/11/24 01:06:55 [warn] 2680#0: duplicate MIME type "text/html" in /etc/nginx/nginx.conf:39
2015/11/24 01:06:55 [warn] 2680#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
But they seem to be warnings rather than severe show stoppers.
Are there any other files that I should be taking a look at?
As another point of reference, I've looked at this SO Post which would seem to imply that I need to enable SSL in order for all of this to work.
Thanks in advance!

Got it.
In my 'production.rb' I had a force_ssl setting and I didn't set up SSL yet since I was just starting out.

Related

Precompiled assets not loading in rails app deployed to AWS elastic beanstalk

this is a question that pertains to deployment of rails application on AWS elastic beanstalk. When I type eb logs in console, I get the following error under /var/log/nginx/error.log:-
2017/06/04 06:02:08 [error] 31759#0:
*1 open()"/var/app/current/public/assets/trumbowyg.min.css" failed
(2: No such file or directory), client: 172.31.79.121, server: _,
request: "GET /assets/trumbowyg.min.css HTTP/1.1",
host: "kanttly-dev.kfzi8ynhke.us-east-1.elasticbeanstalk.com",
referrer: "http://kanttly-dev.kfzi8ynhke.us-east1.elasticbeanstalk.com/"
However, when I eb ssh and cd /var/app/current/public/assets/ && ls, I can see the precompiled files in the directory.
trumbowyg.min-65157a3a7fa7c31aa4e2b9e7036c1e389339f4f7964eece797770708df9d2ca1.css
I would be glad if there were anyone who can explain to me what the problem is since the asset(trumbowyg.min.css) is already pre-compiled and how I can load the precompiled asset. Thank you!

Rails file upload issue due to Phusion Passenger tmp folder rotation

I have a problem with a rails app running on a newly set up server. The rails app runs on ubuntu/ngnix/passenger.
OS: Ubuntu 12.04.2 LTS
Webserver: ngninx 1.5.4
Passenger v 4.0.24
When uploading larger files through the rails app, when the upload finishes, the app throws a "502 Bad Gateway" error. This only happens for bigger files.
The error log from nginx looks like this:
2014/10/07 14:03:21 [crit] 24511#0: *339 connect() to /home/.../tmp_passenger/passenger.1.0.14062/generation-15/request failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: www.xxx.com, request: "POST /path HTTP/1.1", upstream: "passenger:/home/.../tmp_passenger/passenger.1.0.14062/generation-15/request:", host: "www.example.com", referrer: "http://www.example.com/path"
Now, when looking into the folder in /home/.../tmp_passenger/passenger.1.0.14062/generation-15 the generation-N folder seems to be rotating exactly every 60 seconds from .../generation-11 to .../generation-12 and so forth.
Now, obviously any upload - for which passenger uses this generation-N directory as tmp – will fail if it takes longer than a minute, or hits this rotation by chance on shorter uploads.
Now, I really don't know where this rotating of the generation-N folders is happening/configured. I'm pretty sure this is what I need to fix this annoying issue.
From Googling I have the impression that either:
systemd-tmpfiles-clean.service is responsible for the rotation. (but how to change the timing of 60 secs in that case?)
or the respawning of passenger somehow invokes a rotation of the generation-N folder although the PID stays the same so I don't think it's a complete restart of passenger responsible here.

Upload a file on server [internal error 500]

On ruby on rails I have written a code where I can upload a file on the amazon console, when i run the code from the localhost i am able to upload the file successfully . But i try to upload it from the swagger i am getting a error called : internal error 500. I have checked the log file and found the following error:
/2013/12/23 09:34:05 [crit] 1705#0: *315335 open() "/tmp/passenger-standalone.1627/client_body_temp/0000000007" failed (2: No such file or directory), client: 10.29.36.248, server: _, request: "POST /v1/models/GTAG2/modelfirmware.json?api_key=5rx2mR3muK1mCydYerw3 HTTP/1.1", host: "dev-api-3.elasticbeanstalk.com"
Can anyone tell me how to fix this bug? In my S3 the folder and bucket is available.
Sounds like you may be encountering issues similar to one of the following:
Phusion-Passenger Issue #654 where something (a daemon) is deleting (cleaning) /tmp files while they are still in use.
Issue Uploading Files from Rails app hosted on Elastic Beanstalk
I'd check to make sure nothing is running on your system that could be deleting/cleaning files under /tmp while Passenger is running.

rails 500 error no production log entry

I have installed a new rails application on the same server as another application. The original is running fine but the new application gives me the infamous "We're sorry but something went wrong" but there is no entry in production log. The last entries in production log are from my migration using rake.
I have found if I run cap deploy:cold it will work but then on the next yupdate will fail again with no sock file. Then cap deploy:cold seems to be required on each update.
edit: If I run /etc/init.d/unicorn_taxidata restart I get "couldn't reload" then if I run it again immediately it starts fine.
The app works in development. Environment is NGINX, unicorn, postgresql, rails 4.0.0.0, ruby 2.0.0p195.
I have this error in my nginx error log:
[crit] 889#0: *65 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 1.123.13.26, server: myapp.com.au, request: "GET /login HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/login"

Problems with Passenger + Nginx: Failed to connect to a master node. Rails config error?

We're not sure if this is something not configured properly in our Rails setting, but we're seeing this error in our nginx error logs get repeated: Exception PhusionPassenger::UnknownError in PhusionPassenger::Rack::ApplicationSpawner (Failed to connect to a master node at x.objectrocket.com:10804 ...
Here's a gist with more from the error log: https://gist.github.com/panabee/a291526f4dcf4cd434d9
How do we stop these errors?
We're on Rails 3.2.12.
This error means the ObjectRocket mongo server is refusing or timing out your connections. Contact them with the specific logs to work out why they refuse the connection.
Also, try setting your timeouts lower to avoid hanging connections for your clients:
MongoMapper.connection = Mongo::Connection.new(host, 27017, :connect_timeout => 1, :op_timeout => 1)
This sets the connect and read timeouts. There's a :timeout option as well: it's related to connection pooling, not connecting to the server.
Neither :op_timeout nor :connect_timeout have a default value. Verify their settings by reading MongoMapper.connection.connect_timeout.
If you're using the 1.8.0 mongo gem version or later, you may want to replace the deprecated Mongo::Connection class with Mongo::MongoClient.
Try to add
# encoding: UTF-8
In the first line of environment.rb.

Resources