Mongrel server trying to perform GET on 127.0.0.1 - ruby-on-rails

I've recently started a Rails 3 project which I checked out from github. The application uses subdomains to access accounts so I had to perform a small change in my etc/hosts/ file so that the app navigates properly. I'm now trying to login to the app but am seeing a very strange request in the terminal:
Started GET "/session/new" for 127.0.0.1 at Sun May 08 13:48:38
I'm using the mongrel server and its running on ip 0.0.0.0 so I can't figure out why the app is looking up 127.0.0.1. I'm on OS X so ive stopped my local apache server too.
I've removed all traces of the string "127.0.0.1" in my app but still see the request being made to that IP.
Does anyone have any idea's as to why this is happening?
EDIT: Hosts file is as following:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost ger.mpt.local
255.255.255.255 broadcasthost
#::1 localhost
#fe80::1%lo0 localhost
EDIT: I should also mention that I get a 302 redirect status from firebug when I submit the login form.
Thanks,
gearoid

Mmm. 0.0.0.0 means that Mongrel listens on every IP address "associated" with your system, including localhost (localhost is defined as an alias to 127.0.0.1 everywhere).

The answer to this lay in the session storage configuration.
After debugging through the code I could see that the session wasn't being made readily available to various authentication methods. Upon deeper inspection I found a config file which set the domain which the session is picked up from. Setting that to "mpt.local" allowed the session to get picked up and thus allowed me to login.

Related

ERR_TOO_MANY_REDIRECTS after change .dev domain to .test in /etc/hosts for rails app

I wanted to change development domain to .test from .dev for our rails app after new Chrome update that forces https for .dev domains.
I updated all spots in the app where we were using .dev domain. I changed /etc/hosts file too. It looks like below. I get ERR_TOO_MANY_REDIRECTS error when try access the app in a browser. I see in logs that this request does not hit the app, so it probably fails somewhere earlier. Any ideas how to fix this?
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 example.test
127.0.0.1 www.example.test
127.0.0.1 app.example.test

Is there another way to demonstrate 127.0.0.1 page

I'm editing the hosts file by say adding 127.0.0.1 somesite.com
When I am navigating this site (somesite.com) access to this site will be blocked.
Can I actually edit the info which will be shown in browser when it is blocked?
127.0.0.1 is the loopback address, meaning that it will attempt to open port 80 on the local machine on which the host file resides. If you want to customize the page that is displayed then you will need to install a webserver of some variety on the same machine.

`rails server` using Puma and domain name pointing to 127.0.0.1

I have a Rails application that uses subdomains (legacy application, I've been wanting to change that, not yet). I deployed my app to Heroku and I've started to test Puma because it's the recommended choice for Heroku and the default in the upcoming release of Rails. When I used WEBrick (locally) I was able to test my subdomains using a DNS record that pointed to 127.0.0.1 such as vcap.me, specifically http://vcap.me:3000/ would point to my app and http://abcde.vcap.me:3000/ will correctly set the subdomian to "abcde".
Simply adding gem 'puma' to my Gemfile and runnning bundle, causes rails server to start Puma. Except none of the test domains work: http://localhost:3000/ works, but not http://vcap.me:3000/ or http://lvh.me:3000/
Chrome simply says:
"This webpage is not available
ERR_CONNECTION_REFUSED"
Firefox:
"Unable to connect
Firefox can't establish a connection to the server at vcap.me:3000.
..."
I haven't found a cause/solution, but I suspect it has to do with non HTTP TCP requests supported by Puma, except right know, I'm simply trying a HTTP request through the browser.
Just for the curious, if you haven't heard about vcap.me and similar domains, it's simply a DNS record that points to localhost:
$ dig vcap.me
...
vcap.me. 3048 IN A 127.0.0.1
...
$ dig a.vcap.me
...
a.vcap.me. 3600 IN A 127.0.0.1
...
I feel ashamed, #maxd posted a solution to a very similar question: https://stackoverflow.com/a/28745407/637094 and it works. I still don't understand why I need to bind to vcap.me and I didn't before when I used WEBrick.
rails server -p 3000 -b vcap.me
I'll leave the question open, so maybe someone can expand and we all get a better picture of what's going on
This was issue #782 in the Puma server that was solved on July 18, 2016 here.
Your use of domains like vcap.me was not the issue. That domain be resolved to 127.0.0.1 by the DNS server. The issue was, before it was fixed, that on some systems Puma would by default bind only to the IPv6 resolution of localhost, i.e. ::1. Since vcap.me does not provide a IPv6 resolution, you could not reach Puma by calling http://vcap.me:3000/.
Your observation that rails server -p 3000 -b vcap.me solved the issue is because that is equivalent to rails server -p 3000 -b 127.0.0.1. After that, the server's address matched the IPv4-only name resolution of vcap.me.
Anyway, it's an issue of the past. Now by default, Puma binds to both the IPv4 and IPv6 resolutions of localhost.

Connect Ruby/Rails to ipad via local network

host ip: 192.168.1.2
ipad ip: 192.168.1.3
when working on my host, the web address is: localhost.dev:3000/sign_in/
When I try to connect to my ipad via 192.168.1.2.dev:3000/sign_in the connection times out.
One method to overcome my issue was to change the wifi settings on the ipad to manual proxy:
server: 192.168.1.2
port: 3000
Now 192.168.1.2.dev works! Kinda...
I can now log in to my site, but js seems to be broken and the ipad changes the url to: ( http://2.dev/page ) Normally it would be ( http://localhost.dev:3000/page ) Which I believe is the last digit of the host lan ip. We use some externally hosted js files. Which may be why it is breaking. I can NOT browse the internet (on ipad) while the proxy is enabled. What am I missing?
(192.168.1.2:3000 does not work for any device..)
After further debugging I believe it is because of internet connectivity through the proxy.
The exact error my log spits out is:
CONNECT configuration.apple.com:443 HTTP/1.1
Host: configuration.apple.com
User-Agent: ubd/289.3 CFNetwork/672.1.14 Darwin/14.0.0
Connection: keep-alive
Proxy-Connection: keep-alive
2015-04-20 11:52:54] ERROR TypeError: can't dup NilClass
/home/pete/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httprequest.rb:279:in `dup'
So I think I have to enable linux to forward my internet as well?
Rails is not accessible, because the server binds to localhost.
Here's my usual workflow using zeroconf / Bonjour and Mac OS X, although it should basically work with another OS and / or a fixed IP address, too.
Open System Preferences > Sharing to look up your computer's .local name:
Add the host name to config/environments/development.rb so you access the server by that name, e.g.: (required for Rails 6+ see: Blocked host Error)
Rails.application.configure do
# ...
config.hosts << 'stefans-mac.local'
# ...
end
Start rails server with the -b option to provide the host name (this is the important part):
$ rails s -b stefans-mac.local
=> Booting Thin
=> Rails 4.2.1 application starting in development on http://stefans-mac.local:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on stefans-mac.local:3000, CTRL+C to stop
Assuming you've enabled iCloud Tabs, visit the URL on your Mac using Safari (so you don't have to enter the address manually on your iPad)
On your iPad / iPhone, open Safari, tap the Tabs icon, scroll down and select the Rails tab:
Done:
I'm not sure what Ruby on Rails version you're on but somewhere around version 4, Rails changed the default binding address from 0.0.0.0 to only localhost. By default this allows you to only access the Rails app via localhost:3000 or 127.0.0.1:3000 - which is fine in most cases.
Now if you'd like to access the app from an iPad on your local network (or any device on your local network) you can use the -b option when starting the server and specify a binding address of 0.0.0.0
rails s -b 0.0.0.0
This will bind on ALL interfaces including localhost and the IP assigned by your network. You should now be able to access the app via your iPad. Hope this helps.
If I were you, I would try Ngrok. that way you can temporarily and securely expose your dev machine's localhost:3000 to the ipad. Download ngrok to your application's folder and unzip /path/to/ngrok.zip.
For me that looks like:
unzip ngrok_2.0.16_darwin_amd64.zip
Then run rails s.
Finally ./ngrok http 3000.
This command will give you an address to hit from your ipad. When you're done just kill ngrok with ctrl+c.
I get the following output:
NAME:
ngrok - tunnel local ports to public URLs and inspect traffic
ngrok by #inconshreveable (Ctrl+C to quit)
Tunnel Status online
Version 2.0.16/2.0.15
Web Interface http://127.0.0.1:4040
Forwarding http://014da213.ngrok.io -> localhost:3000
Forwarding https://014da213.ngrok.io -> localhost:3000
Connnections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Type the forwarding address into your ipad. For me, http://014da213.ngrok.io
No config required!
192.168.1.6 is an ip address, eg the address of your computer on the local network.
:3000 is a port number (well, 3000 is the number, the ":" just separates it from the ip address), in this case the port which Rails runs on.
localhost.dev is an alias set up on your machine, probably for 127.0.0.1 which is the standard "this computer, ie the 'local host'" ip address.
I wouldn't have expected 192.168.1.2.dev to work at all because it's not a valid ip address - it's an ip address with the last bit of your alias on the end.
You should use "192.168.1.2:3000" on your ipad to connect to your local computer's rails server. You shouldn't need to change your proxy settings (so set them back to normal).
If you specifically want to use a particular domain name on your ipad (when you access your rails app), which can be useful if your app displays the site differently based on the domain or subdomain that it was accessed via, then you can use the awesome http://xip.io/ . This is probably more complicated than you need though, it sounds like you just want to see what your rails app looks like on an ipad.

I can't see anything while running Rails server or Node server

I'm in a big problem, I can run my Rails or Node servers, but when I look into the browser, Chrome tells me that can't acces into localhost page.
I tried modifying the hosts file in C://Windows/System32/drivers/etc/hosts
I have removed the comments to:
127.0.0.1 localhost
::1 localhost
But nothing happens, when that lines are in comments Apache works, but not Rails or Node.
I don't have any proxy, I triedd with differents ports, and I don't know what else to do.
I would appreciate any advice

Resources