Rails on EC2 - Puma responds, but page never loads on browser - ruby-on-rails

Firstly, cheers! This is my first post here on Stack Overflow, I'll try not to do anything silly :). I've spent the last 3 days banging my head against this issue and googleing away, but never really found a solution, however basic it may be.
I've set up a fresh EC2 instance (running Ubuntu 16.04) and created a new Rails (v 5.1.6) app with a simple scaffold:
rails new test_app
cd test_app
At this point, Rails complained that I had to install the 'listen' gem, which I did (v 3.1.5). I then proceeded as follows:
rails g scaffold article title:string
rails db:create
rails db:migrate
So far so good. I then went on to configure AWS's security groups and properly allow TCP connections through port 3000. I'm currently using Puma (v 3.7) as a server.
Here's whats bugging me: I then ran
rails server
and tried to connect to my EC2 through Chrome on port 3000. Turns out that I was able to get to the usual "You're on Rails" page, no problem, but when I tried to get to any other pages, say /articles or /articles/new, I got a positive response from the server in the console:
Started GET "/articles"
Processing by ArticlesController#index as HTML
Rendering articles/index.html.erb within layouts/application
Article Load (0.7ms) SELECT "articles".* FROM "articles"
Rendered articles/index.html.erb within layouts/application (47.3ms)
Completed 200 OK in 3912ms (Views: 3807.5ms | ActiveRecord: 1.5ms)
But the browser keeps waiting forever for a response. I also tried accessing the URL through curl and got no response as well. I'd appreciate if anyone could let me know how stupid a mistake I'm making here.
Thanks,
Márcio

Firstly, cheers you explained your problem very well
when you deploying your app on EC2 then this isn't the right way to do but still it should give you response in browser. Please make sure your port 3000 isn't blocked. Go to network interface -> select your instance carefully -> in front of Security groups check your inbound rules and make sure port 3000 is open
Above explanation is just to answer whatever you are trying to do. Although this should not be the proper way. Proper way should (in short ) be running your ruby on rails application with a rack server (puma, thin, etc) behind a web server Apache or Nginx .

Related

Rails Server-- clearing unwanted logs in rails server

when ever I am using my app in local machine I have to on the server
$rails server
each time I do something in my app in the browser all the assets, jquery logs appear in the terminal like
Started GET "/assets/jquery.ui.core.css?body=1" for 127.0.0.1 at 2013-10-11 12:38:44 +0530
....
.....
and so on like this .
If i dont want to see them in my logs each time what should I do?
Am new to Linux
Possible this How to disable logging of asset pipeline (sprockets) messages in Rails 3.1? is the answer your question.
Briefly, you can use this gem: https://github.com/evrone/quiet_assets

net/http rails issue works only in console

in ruby on rails console 'net/http' works, but in controller it doesn't and gives timeout error.
require 'net/http'
uri = URI('http://localhost:3000/api_json.json')
json = Net::HTTP.get(uri)
parsed_json = ActiveSupport::JSON.decode(json)
Most likely you're using default Webrick server, that serves one request a time. So, from console it works fine, but fails when you try to call it from controller (when the Webrick worker is already busy).
You can try to setup and run another server like unicorn or thin, or run two Webrick instances on different ports:
rails server
rails server -p 3001
and go to localhost:3001
#dimuch's solution might have solved your issue, but it might help someone facing similar situation. I will explain the issue, and the solution in detail (extension of #dimuch's solution).
Issue:
You might have a controller like some:"/test_controller/test_method", and you might want to call a method in a controller, like /api/v1/some_test_api, and facing error like Completed 500 Internal Server Error in 60004.4ms
[27580c5c46770812c550188346c2dd3e] [127.0.0.1] [/xauth_test/sanity_oauth_login]
Timeout::Error (Timeout::Error):
Solution:
As said by #dimuch, "
Most likely you're using default Webrick server, that serves one request a time.....". 1. You need to run the application on different ports, like
rails s -p 3000, and rails s -p 3001, then make the request from 3001.
If you face an issue like "A server is already running. Check /tmp/pids/server.pid. Exiting", then try running rails s -p 3001 -P PROCESS_ID.
2. Use other server's like Unicorn, or Puma.
Note: If you want it for just testing purpose in local, then I would suggest to go with the first solution, which is easy and simple. I am sorry for poor English, and I found most of solutions from other stack overflow pages, and websites, which I am attaching (links for refs) below, and sorry if I missed some one or some thing to refer. Hope this helps someone.
Refs:
For running multiple instances:
Running multiple instances of Rails Server
Similar errors and way they are handled:
Rails HTTParty Getting Timeout::Error
Faraday timeout error with omniauth (custom strategy)/doorkeeper
Strange Timeout::Error with render_to_string and HTTParty in Controller Action
Configuring Unicorn &Puma:
http://vladigleba.com/blog/2014/03/21/deploying-rails-apps-part-3-configuring-unicorn/
https://github.com/puma/puma

Rails 3.2 PrivatePub in production faye.js not found

I'm having an issue with a gem called private_pub that uses a faye gem and thin server.
This all works fine in development, but on the server I can get everything started up fine but on the page where I'm using private_pub I get an error in the js console (chrome) that says
GET http://myapp.example.com/faye.js 406 (Not Acceptable)
and when I view http://myapp.example.com/faye.js in the browser (url changed) I get an empty screen where in development it displays all the js code. Also I can see in chrome's developer tools I can see in development the type is "Pending" and in production I'm seeing it passed as "text/html"
I've googled and googled and have come up with exactly nothing. Can anyone point me in the right direction.
Is there some special mime-type that is being passed here that I need to configure apache or rails to accept?
Thank you in advance
HAZZAH!
I figured it out.
I jumped through all kinds of hoops and am not 100% sure that the solution I found isn't working because of some of the other things I tried but...
First thing I tried was following a tutorial for installing Thin with a Rails app on Centos, (from Slicehost's docs) Slicehost Articles: CentOS - thin web server for Ruby and did a whole bunch of thin configurations. But I don't believe this was necessary because private_pub/faye is supposed to handle this all for you. (from what I understand)
One important thing is that I know you need to use the startup that private_pub describes, even though you can start thin directly.
RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -D -E production
The '-D' makes sure that it runs as a background process.
In my private_pub.yml:
production:
server: "http://myapp.example.com:9292/faye"
secret_token: "{SECRET_TOKEN HERE}"
signature_expiration: 3600 # one hour
I added in the port# here and it all works now.

thin slow in development when not using localhost

I switched to using thin in local development instead of webrick.
When I access localhost:3000 it returns the page almost instantly just like webrick
But when I access myapp.local:3000 the browser spins for 20 seconds or so on each request before rendering the page. I'm not sure what it's doing during that time - the rails log shows the page being generated almost instantly - it almost seems like the browser is doing name resolution during that time or something else.
In my /etc/hosts i have
127.0.0.1 myapp.local
In webrick there was no difference between accessing myapp.local:3000 and localhost:3000.
But in thin there is the large difference mentioned above. Any theories? Much appreciated!
Look for the file /usr/lib/ruby/VERSION_OF_RUBY/webrick/config.rb and edit it.
Replace/insert the following line as a new key of the General hash.
:DoNotReverseLookup => true
Restart webrick.
Otherwise try running sudo service avahi-daemon stop
See Webrick is very slow to respond. How to speed it up? for more details

Spree error 500

Need some help here.
I have deployed spree (0.70.3) on slicehost (ubuntu, ruby1.8.7, Rails
3.1.3), installed the spree gem, loaded in the sample data
successfully following the steps on spree startup manual and I am
using passenger (it works on localhost:3000). When I upload to my
server, however, instead of seeing the spree interface, I am getting
an error message. From the production.log:
Processing by HomeController#index as HTML Completed 500 Internal
Server Error in 22ms ActiveRecord::StatementInvalid (Could not find
table 'product_groups'):
Any suggestions how I can get this to work?
Website: http://www.nutxboutique.com
production.log is the rails log. It appears your problem is occurring before rails completes loading. If you're using apache, check/post the apache logs, it might have more clues as to what's going on.

Resources