开发者

Access WEBrick from a different PC

开发者 https://www.devze.com 2023-01-27 20:24 出处:网络
I used: rails s run webrick on 0.0.0.0:3000 But I could\'t reach the web application from 开发者_运维知识库another PC.

I used:

rails s 

run webrick on 0.0.0.0:3000

But I could't reach the web application from 开发者_运维知识库another PC.

How can I achieve this in Rails 3?


The default binding IP is 0.0.0.0, so the problem can be your firewall blocking that port. Try to use rails s -b IP_ADDRESS -p PORT to be sure the problem is with your firewall.

Btw. Linux, Osx, Windows?


Nucc got it right. You should be able to access the website via your IP address but from what I understand you are trying to reach it via 0.0.0.0 (I was mistaken thinking this is a null address, my bad) as Nucc correctly states 0.0.0.0 maps to INADDR_ANY so will map to all of your network interfaces.

If you want to specify a specific IP address use (assuming your IP address is 192.168.0.50):

rails s -b 192.168.0.50

I would keep the default port at 3000 just so you don't conflict with a real web server if you're running one on your computer but if you aren't feel free to change it to 80 like so:

rails s -b 192.168.0.50 -p 80

The -b command line parameter changes the IP address WEBrick binds to and the -p parameter changes the default port. For a full list of options type:

rails s -h

As has also been stated you need to make sure the port is open if you're using a software firewall. If you weren't trying to use 0.0.0.0 but were using the correct IP address from the second computer then this is probably the culprit.

Now to get to your rails site from another computer you would simply type in a browswer:

http://192.168.0.50:3000

Or if you've changed the default port to the standard port of 80 you could just use:

http://192.168.0.50


(sorry, I can't reply :()

"The default binding IP address is 0.0.0.0 which can't be reached from another computer since that's a non-routable address."

Sorry, but it's not true. Here the 0.0.0.0 means INADDR_ANY, so it binds to all interfaces...


If connections are through the LAN, then use the command ifconfig on your terminal find the inet address, it will something like 192.148.0.100, and use it 192.148.0.100:3000, 3000 is the port where the server is running.


Make sure you don't have a firewall blocking that port. Also make sure that you include the port when you're trying to hit it from the other machine. It should Just Work as far as rails goes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号