I build up a rails app in mac OS and try to use other device (in same private lan) to connect to this local service. However my device can not access to this url => "http://192.168.1.107:3000"
My console is below:
chris$ rails server --binding=192.168.1.107
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://192.168.1.107:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
It works fine in local machine both "http://localhost:3000" and "http://192.168.1.107:3000" but other device still can not access "http://192.168.1.107:3000"
Any suggestion for that? thanks a lot!
Try this:
rails server -b 0.0.0.0 -p 3000
If firewall blocks 3000 try this:
rails server -b 0.0.0.0 -p 80
Now access [your-computer-ip]:80
You could also use a service like https://localtunnel.me/ (if you are not on the same local domain)
Related
I have a rails staging server available to my LAN as follows:
rails server --binding=0.0.0.0 -p 3000
I would now like to open up a second, concurrent rails server to my LAN as follows:
rails server --binding=0.0.0.0 -p 3001
Unfortunatly, I am getting this error message:
...
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
A server is already running. ...
The error only exists if I use --binding=0.0.0.0 on both servers, which is necessary if I want it to be accessible to my LAN.
How can I open up multiple rails servers on the same machine to the LAN, not just localhost?
EDIT:
After trying Vasfed's solution, e.g.
rails server --binding=0.0.0.0 -p 3000 --pid=tmp/pids/server0.pid
rails server --binding=0.0.0.0 -p 3001 --pid=tmp/pids/server1.pid
the problem persists, but this time I have more information. It seems related to a port 9292 being opened...
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:9292
Exiting
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Only one usage of each socket address (protocol/network address/port) is normally permitted. - bind(2) for "0.0.0.0" port 9292 (Errno::EADDRINUSE)
Rails checks if a pid file is already present. To run two copies of single app, you should alter pids too:
rails server --binding=0.0.0.0 -p 3000 --pid=tmp/pids/server1.pid
rails server --binding=0.0.0.0 -p 3001 --pid=tmp/pids/server2.pid
I am having difficulty getting rails up and running. I have gotten as far as booting it with the command
rails s
This results in the following output:
=> Booting Thin
=> Rails 3.2.22.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
installing dummy notifier
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
When I run localhost:3000
I had the line:
config.vm.network "forwarded_port", guest: 80, host: 8080
in my vagrantfile but tried to change this and ran
vagrant provision
but to no avail. Are there any ways for me to test why I cannot access the project. Any guidance would be appreciated. Thanks!
UPDATE:
Having run the command:
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
I received a few errors regarding deprecation and "ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation 'capabilities' does not exist"
Would this have anything to do with it not loading correctly?
In your vagrantfile, try to use:
config.vm.network "forwarded_port", guest: 3000, host: 3000
You don't need to run vagrant provision to change port forwarding, you can just restart the box with vagrant reload.
Rails defaults to only binding to localhost, and won't allow connections from other hosts (even a browser on your port-forwarded host). Try starting the rails server binding on all addresses like this:
rails s -b 0
I've tried to kill my rails server using this article from cloud 9.
I'm using the gem thin and everytime I try to run cloud server command I recieve this error
rails s -b $IP -p $PORT
=> Booting Thin
=> Rails 4.2.6 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:8080, CTRL+C to stop
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:530:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
from /usr/local/rvm/gems/ruby-2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:530:in `start_server'
from /usr/local/rvm/gems/ruby-2.3.0/gems/thin-1.6.4/lib/thin/backends/tcp_server.rb:16:in `connect'
from /usr/local/rvm/gems/ruby-2.3.0/gems/thin-
full error
It seems the port 8080 is in use, to find the PID using the port, run :
netstat -tulpn | grep :8080
Then you can kill -9 <PID>
This error says, 8080 port already in use, you may need to use different port for you application
Update:
Try to kill the existing process. Find port number using this command ps -ef | grep thin and then kill it kill -9 <port>. Try running your app now.
I just changed from thin to puma at the recommendation of Heroku. When I start my rails app using the puma server it responds:
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
However if I go to http://0.0.0.0:3000 in the browser, which was my old localhost with the thin server, it does not respond. However, if I open http://localhost:3000, then it works. It appears that the definition of localhost has changed.
So, what is localhost? In particular, what sort of object is it, how is it defined, how do I see the actual ip address, and why does puma change it?
If you're trying to get Rails to bind to a different ip, the way to do that is with the -b option. To bind it to 0.0.0.0 instead of the Rails-default localhost you'd want to run something along the lines of rails s -b 0.0.0.0
Note: To be explicit, it may not be a bad idea to throw the -p 3000 option in there too (sets the port), even though that default is not likely to change. More info on the available options can be found by running rails s -h as well.
Localhost is the IPv4 loopback IP address 127.0.0.1. It is used instead of the hostname of a computer. Localhost can sometimes mean this computer.
For example, directing a web browser installed on a system running an HTTP server to http://localhost will display the home page of the local website.
Here's an interesting Wikipedia article
https://en.wikipedia.org/wiki/Localhost
I don't understand why it's not running on port 80 instead of port 3000 when I run the command RAILS_ENV=production rails s on the same line. I want it to run in production mode but it's not running on the correct port. Anyone know why? I'm trying to use Rubber but I haven't ran any commands for it only just changed some of the files like it says in this tutorial.
root#ip-000-00-00-000:/home/ubuntu/Git/# RAILS_ENV=production rails s
=> Booting Thin
=> Rails 3.2.11 application starting in production on \http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
\>> Thin web server (v1.5.1 codename Straight Razor)
\>> Maximum connections set to 1024
\>> Listening on 0.0.0.0:3000, CTRL+C to stop
^C>> Stopping ...
Exiting
webrick runs on port 3000 by default(even in production mode). Pass the port number explicitly if you want to run on a different port.