I have a local ruby on rails server set up on -
http://localhost:3000/
I have added allow arbitrary loads in the info.plist
When I run the app on the simulator it works fine, but when I try to run it on the iPhone it doesn't. The app just crashes.
Looking at similar questions I found that I need to use the actual IP. I also turned the Internet sharing on from the preferences.
So I found out my local IP address which is - 192.168.0.8
So in Safari I am testing it out like this http://192.168.0.8:3000/
But it doesn't work!
How can I get this up and running?
Start your rails server like this:
rails server -b 0.0.0.0
Note that if you have a firewall on your computer you may need to open your firewall or run on another port, like port 80.
rails server -b 0.0.0.0 -p 80
It'd be easier if you Ngrok.
Just start your server, as usually and by default with port 3000, and then run ngrok as to start listening on such port:
./ngrok http 3000
This will give you a public IP which will be accessible for your devices.
Related
I'm trying to run a simple web server on a Raspberry Pi with Flask. When I run my Flask app, it says:
running on http://127.0.0.1:5000/
But when I enter this address on my laptop's in Chrome, I get
ERR_CONNECTION_REFUSED
I can open 127.0.0.1:5000 on the Raspberry Pi's browser. What do I need to do to connect from another computer?
Run your app like this:
if __name__ == '__main__':
app.run(host='0.0.0.0')
It will make the server externally visible. If the IP address of the machine is 192.168.X.X then, from the same network you can access it in 5000 port. Like, http://192.168.X.X:5000
when you are running the server via flask run change it to flask run --host=0.0.0.0
to connect, find the IPV4 address of the server that your script is running on. On the same network, go to http://[IPV4 address]:5000
A reason could also be in firewall refusing incoming connections on port 5000. Try:
sudo ufw allow 5000
app.run(host='0.0.0.0',port=5000)
if you run your app in this way then your server will be visible externally.
Steps by Setp:
Run your app by using the following command
app.run(host='0.0.0.0',port=5000)
Go to the window cmd . Type ipconfig and get the get the IPV4 adress suppose your IPV4 address is 192.168.X.X
Go to the mobile browser and type the 192.168.X.X:5000
If you have debug = True inside your app.run(), then it will not be visible to other machines either. Specify host and port inside app.run() without the debug = True.
You will have to run the development server such that it listens to requests on all interfaces and not just the local one
Ask Flask to listen on 0.0.0.0:PORT_NUMBER
or any other port you may choose
On MacOS 12.4 (Monterey) I couldn't load localhost nor my local IP but it worked with both of these:
0.0.0.0
127.0.0.1
Just change the URL in the browser if it loads with "localhost".
Both devices must be connected to same network.
Use app.run(host='0.0.0.0',port=5000) and run with your own Ipv4
address like his http://[Your Ipv4 address]:5000
If you are connecting this with android app then don't forget to
put INTERNET permission in manifest file.
Contrary to popular believe 127.0.0.1 is not the same a localhost.
I solved the issue above by setting 127.0.0.1 explicitly on both ends.
Well i was also here to know answer but i guess i found out problem. The reason is that you may not activated or run flask that's why it is showing error. For that you have to start from terminal "flask run" and then surely your flask will run...
The issue may occur, if VPN is on, so try to switch it off.
I recently have been having a problem with my AWS EC2 instances. The problem is that I cannot hit my Rails servers via public IP, but I can hit localhost and the server will respond.
Here's what I'm doing:
Create new EC2 instance (t2.micro, ubuntu free tier)
Security group has port 22, 80, 3000 open to everyone (0.0.0.0)
SSH to EC2 instance, install rails (I've been using this to install)
Start rails server after install, it's running on port 3000
run "wget localhost:3000" and it returns index.html, yay!
go to my web browser, type in EC2 instance public IP and port 3000 (IP:3000), says it can't connect :(
kill rails server, restart it on port 80, wget works but can't connect via public IP
as a sanity check, I install nginx and run it, and can see the nginx start page on port 80 via public IP... so confused...
So I'm thinking it has something to do with how I'm installing Rails, but I've tried methods other than using that install script but am encountering the same problem... I've even tried creating an entirely new AWS account just in case I screwed up the settings in my original account but haven't had any luck. I have previously been able to get rails running on EC2 instances just fine (in fact I have EC2 instances using the same security group running on my AWS account right now and can hit those public IPs just fine), but am now just banging my head against the wall... any help would be greatly appreciated!
EDIT: For now, I've configured nginx to hit my rails server.... at least that works for now... although I'm still curious why I can't hit my rails server directly...
Check if rails listens on 0.0.0.0 or 127.0.0.1, default is to listen only on localhost.
-b, --binding=IP Binds Rails to the specified IP.
Default: localhost
From the Ruby on Rails 4.2 Release Notes:
Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. This should have minimal impact on the standard development workflow as both http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before on your own machine.
If you are using 'rails server' and want to use the default port 3000 then use below:
sudo rails server -b 0.0.0.0
it can be accessed as http://[public_ip]:3000.
If you want to use it as a URL without the port use the below to run the server:
sudo rails server -p 80 -b 0.0.0.0
You just access it as http://[public_ip].
I was running the rails server on default port 3000 on my AWS Ubuntu instance and had allowed this port in the security group, inbound section but still I was unable to access my application by using this.
http://public_ip:3000
I searched a lot and this answer helped me. Explaining the answer. We have to make firewall setting flexible so that our firewall allows port 3000.
You can use this command to check if this port is allowed on firewall or not.
$ sudo iptables -L | grep :3000
If you see nothing it means we have to allow it using this command.
$ sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
This worked for me to get my rails app access on port 3000.
My home server is running on Raspberry Pi with Rasbian (Debian for ARM)
There rails server is running: rvmsudo rails s -b ${LOCAL_IP} -p 80
It works perfectly fine to access from local machines, but it is not working when I am trying to access from outside of my local network
It should not be a router problem as I can easily access that server over ssh (both :22 and :80 are open in router preferences)
If you can access http via your local network ip, then it can be issue with router, look to port forwarding settings of DMZ.
BTW, router can use 80 port for its own purposes, like web interface. Try to bind to 8080 port for example.
As an alternative to share 80 port via internet you can use https://ngrok.com/
It allows you to share localhost http to anyone.
Hello i am trying to access my Webrick rails server that i started on my ubuntu to my windows 7 pc locally. I checked on ifconfig in my virtual box and used the inet:10.0.2.15 when i run my rails server and also used port 80 like this:
rails server -b 10.0.2.15 -p 80
It didn't gave me an error in the terminal but when i try to go to 10.0.2.15 on my windows browser, it says it can't connect. I tried disabling the firewall in windows but still wont work. Thank you.
Choose another network type for your VM ubuntu. I suggest the Bridged Network. Reboot vm, it should obtain ip in same network as your windows host (example 192.168.0.XXX). Then you will be able reach your rails server from network At any port 80 or 3000.
Can you share your ubuntu with the vm, via the apache server too? is that started? In macs you have to enable web sharing (or something similar to that wording). ON ubuntu what happens when you do localhost:80... if i recall it should say it works! or something like that.
I have a rails application running on localhost:3000. I wish to access it from another computer on the same network. I feel like i've done this before with ease, but it's giving me some grief. I can ping the IP of the computer just fine, but hitting ip:3000 in the browser doesnt work. I tried launching rails s -b ipaddress as well, and no luck.
Suggestions?
After making sure your server side firewall is open to the incoming connection on high ports (this is normally true and the default port is 3000, so you probably don't have to do anything) you must also start the server like this:
rails server -b 0.0.0.0
which binds it to the universal address. It binds to localhost by default.
Using this method you don't have to bind to port 80, but you can like this:
rails server -b 0.0.0.0 -p 80
(If you're using rvm then you may need to use rvmsudo)
To make this change more permanent edit your config/boot.rb and add this:
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
Then you should only have to use rails s
Source: https://stackoverflow.com/a/29562898/1795429
rails server -b 0.0.0.0 -p 8000
This worked for me. No firewall issues, and no need to give super user permissions.
Yes, this was a good answer in general:
rails server -b 0.0.0.0
If you use Ubuntu, you probably have to open the port in the firewall:
sudo ufw allow 3000
If your system is running in VirtualBox, you have to check your Network Settings.
In the case of network mode NAT you have to click to the extended options and there to Port Forwarding. Add a rule for TCP protocoll, host port 3000 (or any other), and guest port 3000.
Assuming Webrick starts without issue, this is 100% a firewall issue. You should provide some specifications, like what operating system your host is running and whether or not you have administrator privileges as far as controlling the firewall.
If you're on Linux and running the iptables firewall service, you need to add a rule to accept traffic over port 3000. It would look something like:
iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
That command would be a one-time-only solution though, you'd need to extend your current iptables rules script to make it permanent every time your system boots or logs in.
If you're running Windows, depending on whether you're running XP or Vista/7, you'd need to do something similar. I'm going to assume you're in the Vista/7 environment, and you would just need to follow the steps provided through this guide http://windows.microsoft.com/en-US/windows7/Open-a-port-in-Windows-Firewall.
Try running the server on port 80 instead, your firewall is probably blocking port 3000.
I am using foreman to manage my Procfile-based application.
Adding -b 0.0.0.0 to my bundle exec rails s command in Procfile worked for me.
One reason is your ip is not bind to the rails server. You can bind the ip with -b command option.
Usage: rails server [mongrel, thin etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=IP Binds Rails to the specified IP.
Default: localhost