Simple Webserver Hack
I needed to have a simple webserver for my home network and was not interested in trying to setup Apache. (I’ve done it before, not keen to do it again.) It’s helpful to have read-only access to files that I want to view, not necessarily need to copy wherever I’m working.
I was looking for any easy alternatives to apache and google suggested a python module that I could run easily enough from the command line:
python -m http.server 1234
(1234 is the port number that should be replaced with something usable, like 3001.)
But that worked while I was working, but if I left and the session died, then the webserver went with it. So while I probably could have found a few other ways to do it, I went with the least possible configuration option, tmux.
So whenevever I want to do this, it’s easy:
- Start a tmux session and rename it web
tmux
^B $ web
- Within the session, start the webserver:
python -m http.server 3001
- After checking it works, detach the tmux session:
^B d
I’ve had the same “server” running since Sunday without issue. And if I need a new one, I can a tmux terminal for an additional session as long I remember to use a different port.