Read more

How to run a small web server (one-liner)

Arne Hartherz
November 02, 2015Software engineer at makandra GmbH

Sometimes you just want to have a small web server that serves files to test something.

Serve the current directory

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

On Ruby 1.9.2+ you can do the following ("." for current directory).

ruby -run -ehttpd . -p8000

Python 2.x offers a similar way.

python -m SimpleHTTPServer 8000 .

This is the same way with Python 3.x

python -m http.server

In both cases your web server is single-threaded and will block when large files are being downloaded from you.

WEBrick also offers a simple way Show archive.org snapshot to serve your files via HTTPS:

ruby -r webrick/https -e '
  WEBrick::HTTPServer.new(
    Port: 8000, DocumentRoot: ".",
    SSLEnable: true, SSLCertName: [%w[CN localhost]]
  ).start'

For solutions in many other languages, see the big list of http static server one-liners Show archive.org snapshot .

Running a Rack application

To boot an application that comes with a config.ru, simply run

rackup

Or, if you have installed Passenger Standalone:

passenger start

For HTTPS, use this snippet:

puma -b ssl://localhost:8000
Posted by Arne Hartherz to makandra dev (2015-11-02 12:20)