pantz.org banner
Quick and dirty web servers
Posted on 05-13-2011 01:18:41 UTC | Updated on 05-13-2011 01:42:00 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 -m SimpleHTTPServer 8080

This line 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.

Del.icio.us! | Digg Me! | Reddit!

Related stories


RSS Feed RSS feed logo
About


3com
3ware
alsa
alsactl
alsamixer
amd
android
apache
areca
arm
ati
auditd
awk
badblocks
bind
bios
bonnie
cable
carp
cat5
cdrom
centos
chart
cifs
cisco
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
dns
dos
dovecot
dsniff
dvdauthor
e-mail
echo
editor
emerald
ethernet
ext3
fat32
fedora
fetchmail
fiber
filesystems
firefox
firewall
flexlm
floppy
flowtools
fonts
format
freebsd
ftp
gdm
gnome
greasemonkey
greylisting
growisofs
grub
hacking
harddrive
hba
hex
hfsc
html
http
idl
ie
intel
ios
iperf
ipmi
iptables
ipv6
irix
javascript
kde
kernel
kmail
kprinter
krecord
kubuntu
ldap
linux
logfile
maradns
matlab
memory
mencoder
mhdd
mkinitrd
mkisofs
moinmoin
motherboard
mouse
movemail
mplayer
multitail
mutt
myodbc
mysql
mythtv
nagios
nameserver
netflow
nginx
nic
ntfs
ntp
nvidia
odbc
openbsd
openntpd
openoffice
openssh
openssl
opteron
parted
partimage
patch
perl
pf
pfflowd
pfsync
photorec
php
pop3
pop3s
ports
postfix
power
procmail
proftpd
proxy
putty
pxe
python
qemu
r-studio
raid
recovery
router
rpc
rsync
samba
schedule
scsi
seagate
seatools
sed
sendmail
sgi
shell
siw
smtp
snort
solaris
soundcard
spam
spamd
sql
sqlite
squid
ssh
ssh.com
ssl
su
subnet
subversion
sudo
sun
supermicro
switches
symbols
syslinux
systemrescuecd
t1
tcpip
tcpwrappers
telnet
terminal
testdisk
tftp
thttpd
thunderbird
timezone
tools
tr
trac
tuning
tunnel
vi
wget
wiki
windows
windowsxp
wireless
wpa_supplicant
x
xauth
xfree86
xfs
xinearama
xmms
zdump
zic
zlib