alexhuang91
alexhuang91

Reputation: 91

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?

Upvotes: 3

Views: 908

Answers (2)

matt
matt

Reputation: 79783

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

Upvotes: 3

datasage
datasage

Reputation: 19573

There are two possible causes for your problem.

  1. Your service is only listening to connections on the loopback interface.
  2. A software firewall is running and is blocking connections from outside on that port.

Upvotes: 0

Related Questions