Ruby Sinatra Webservice Running on Localhost:4567 But Not on Ip

Ruby Sinatra Webservice running on localhost:4567 but not on IP

Following worked for me.

ruby app.rb -o 0.0.0.0

Cannot access sinatra app through the local network

Try ruby app.rb -o 0.0.0.0 or ruby app.rb -e production. Either should work.

Ruby: Sinatra: Webservice is not accessible on Thin

Just in case someone arrived at same problem:

it was quite simple...
don't forget to check iptables, in my case it was blocking the incoming connection.

Can't access Ruby server on VM from host machine

I have the network adapter for my VM attached to NAT. I was forwarding ports 443, 22 and 80 to my VM, and accessing my server on those ports works fine. Since I was running the Ruby WEBrick server on the default port 4567, I just had to forward port 4567 from my host machine to my VM as well.

After that change, typing http://localhost:4567 into my web browser served up the content from my Ruby file.

Cannot access local Sinatra server from another computer on same network

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 (e.g. 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

Webservice does not work after being packaged into a Docker image

This issue is happening because Sinatra by default (development environment) listen on 127.0.0.1 which not works in case of external connection to container

:bind - server hostname or IP address

String specifying the hostname or IP address of the interface to listen on when the :run setting is enabled. The default value in the development environment is 'localhost' which means the server is only available from the local machine. In other environments the default is '0.0.0.0', which causes the server to listen on all available interfaces.

So if you will continue on running in development mode, you need to change it to 0.0.0.0, for example:

docker run -p 4567:4567 --name stack eivor/ruby bash -c 'ruby ./app.rb -o 0.0.0.0'

Which can be used in Dockerfile as:

CMD ["ruby", "./app.rb", "-o", "0.0.0.0"]

Or you can use the following within your script:

set :bind, '0.0.0.0'

Then from outside the container you can get the result:

curl -v localhost:4567
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4567 (#0)
> GET / HTTP/1.1
> Host: localhost:4567
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Content-Length: 13
< X-Xss-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Server: WEBrick/1.3.1 (Ruby/2.3.8/2018-10-18)
< Date: Thu, 14 Mar 2019 17:17:20 GMT
< Connection: Keep-Alive
<
* Connection #0 to host localhost left intact
hello, world!

For more configuration check the following: CONFIGURING SETTINGS

Cannot access sinatra app on AWS Windows from remote machine

I was able to solve my issue, so for the sake of completeness I am publishing the answer.

This wasn't a Sinatra issue, but an AWS issue (maybe not really an issue, more like my misunderstanding). I was under the impression that updating the AWS security group for opening the 4567 port will do the trick.

However, it turns out that I needed also to open the port on the Windows Firewall on my Windows AWS instance. After opening the port on the Windows Firewall I was able to remotely connect to my Sinatra app.



Related Topics



Leave a reply



Submit