Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Sinatra on port 80

Tags:

ruby

sinatra

I installed Sinatra and it works but it uses port 4567 by default. I want it to run on port 80.

In an effort to get it to work on port 80, I tried this:

require 'rubygems'
require 'rack/handler/webrick'
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => :production,
  :port => 80
)

get '/' do
  "Hello World"
end

But I get this error:

$ ruby -rubygems index.rb
index.rb:5:in `<main>': undefined method `default_options' for Sinatra::Application:Class (NoMethodError)

Any idea what's going on?

like image 321
Jason Swett Avatar asked Jan 27 '11 20:01

Jason Swett


2 Answers

Can't you just use (http://www.sinatrarb.com/configuration.html):

set :port, 80

Note that in order to bind a socket to port 80, you'll need to have superuser privileges.


And, by the way,

Using Sinatra.default_options to set base configuration items is obsolete

From: http://www.sinatrarb.com/one-oh-faq

like image 74
miku Avatar answered Oct 20 '22 17:10

miku


An alternate way to accepted answer

rvmsudo rackup -p 80

In case one is using RVM to manage Ruby versions, you may not be able to use sudo that easily (or else would need to setup ruby in path).

like image 30
ch4nd4n Avatar answered Oct 20 '22 17:10

ch4nd4n