Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra EC2 Deployment Security Group Error

I am trying to deploy a Ruby Sinatra api onto port 4567 of an EC2 micro instance.

I have created a Security Group with the following rules (and created the instance with said security group):

--------------------------------
| Ports | Protocol | Source    |
--------------------------------
|  22   | tcp      | 0.0.0.0/0 |
|  80   | tcp      | 0.0.0.0/0 |
|  443  | tcp      | 0.0.0.0/0 |
|  4567 | tcp      | 0.0.0.0/0 |
--------------------------------

I bound myapp.rb on port 4567 (the default, but for verbosity):

set :port, 4567

and ran the service:

ruby myapp.rb
[2013-09-05 03:12:54] INFO  WEBrick 1.3.1
[2013-09-05 03:12:54] INFO  ruby 1.9.3 (2013-01-15) [x86_64-linux]
== Sinatra/1.4.3 has taken the stage on 4567 for development with backup from WEBrick
[2013-09-05 03:12:54] INFO  WEBrick::HTTPServer#start: pid=1811 port=4567

Used nmap while ssh'd in the EC2 instance on localhost:

Starting Nmap 6.00 ( http://nmap.org ) at 2013-09-05 03:13 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00019s latency).
PORT     STATE SERVICE
4567/tcp open  tram

Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds

Used nmap while ssh'd in the EC2 instance on the external ip:

Starting Nmap 6.00 ( http://nmap.org ) at 2013-09-05 03:15 UTC
Nmap scan report for <removed>
Host is up (0.0036s latency).
PORT     STATE  SERVICE
4567/tcp closed tram

Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

How do I change the state of the port from closed to open?

like image 731
alexhuang91 Avatar asked Nov 20 '25 16:11

alexhuang91


1 Answers

You’re starting Sinatra in the development environment. When running in development Sinatra only listens to requests from the local machine.

There a few ways to change this, the simplest is probably to run in the production environment, e.g.:

$ ruby myapp.rb -e production

You could also explicitly set the bind variable if you wanted to keep running in development:

set :bind, '0.0.0.0' # to listen on all interfaces
like image 178
matt Avatar answered Nov 22 '25 07:11

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!