简体   繁体   中英

Cannot access local Sinatra server from another computer on same network

I have a simple Sinatra server that I run through textmate but I can't access from another computer on the same network.

I'm running Ruby 1.9.3p327 and Sinatra 1.4.1 on a Mac OS 10.8.3. Firewall is disabled.

I tested the same scenario on different networks and computers.

The computer responds to simple pings but when I try to telnet port 4567 I can't establish a connection.

There was a recent commit to Sinatra that changed the default listen address to localhost from 0.0.0.0 in development mode due to security concerns.

In order to explicitly allow access from the network, you need to either run your app in another mode (eg production), or set the bind option to 0.0.0.0 .

You can do this from the command line using the built in server using the -o option:

$ ./my_sinatra_file.rb -o 0.0.0.0

确保sinatra服务器不仅侦听localhost(127.0.0.1)的ip地址。

I'm chiming in with a little extra information that may help people like me banging their heads against the wall.

I'm on a Windows machine, not a Mac, and I had to open the port I was using (default for Sinatra is 4567) to the public (even though I'm on a university network).

To do this in Windows 10:

  1. Hit the windows key
  2. Search for firewall and hit enter
  3. Go to advanced settings
  4. Click on inbound rules in the top left
  5. Click on new rule in the top right
  6. Click the port option
  7. Enter your port (probably 4567 for Sinatra)
  8. Next
  9. And now pick from domain/private/public.

Now another thing to consider is who can access your web server. If you want anyone, then pick public. I don't know for sure (and would love other's input) how to get only devices on the same public network to connect. You can also allow specific IPs through, but for that I suggest doing some research on your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM