pantz.org banner
Quick and dirty web servers
Posted on 05-13-2011 01:18:41 UTC | Updated on 07-20-2016 23:11:59 UTC
Section: /software/http/ | Permanent Link

Have you ever needed a way to easily transfer some files to someone or just let them browse through an index of some of the files on your hard drive? It not worth setting up a full fledged enormous web server like Apache or Nginx or Lighttpd. Instead I used to use thttpd to do this. I recently found out how to setup a web server that serves out an index of files from the directory it's run from with a Python one-liner.

# python 2
python -m SimpleHTTPServer 8080

# python 3
python3 -m http.server

# ruby
ruby -run -e httpd -- -p 8001 .

The Python lines will run a simple web server on port 8080 and serve out an index page of files relative to the current directory you ran the command from. It will check for index.html or index.htm and if found will serve it out. If it's not found it just defaults to serving a directory index. You can read more about the module here

If you wanted serve out files but use https (SSL/TLS) instead then you could do it with OpenSSL. The difference with the OpenSSL web server compared to the Python web server is that OpenSSL will not give you a directory index from the directory you start the server from. You will have to request each file directly. You also need to execute 2 lines to start the OpenSSL webserver. One to generate the web server cert and one to start the server. Still it's very easy.

# Generate the fake cert in the current dir. Press enter to answer all questions.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem

# Start the server on port 4433 (default) using the cert we just made
openssl s_server -cert mycert.pem -accept 4433 -WWW

This will serve out files relative to the current directory. Since this is supposed to be quick and dirty the security about it is not that great but the connection is totally encrypted so nothing will be sent in plain text over the connection. With the lines above the key generated is in the same directory that we are serving data from so you should move that to a path outside of the web server. There are a bunch of other options for OpenSSL's s_server. Check out the man page with "man s_server".

I use a firewall to whitelist IP's from trusted people since you can't easily password protect these simple http(s) servers. Just a suggestion.

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

comcast

commands

comodo

compiz-fusion

corsair

cpufreq

cpufrequtils

cpuspeed

cron

crontab

crossover

cu

cups

cvs

database

dbus

dd

dd_rescue

ddclient

debian

decimal

dhclient

dhcp

diagnostic

diskexplorer

disks

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib