How do I set up the simplest HTTP local server?
Ubuntu ships using python3 as its default, and they have gone to great lengths to make this extremely easy for us :D
To start the http server on port port simply type
python -m http.server port
If you want to share files and dirs, cd into whichever directory you want to serve
cd /my/html/files
python -m http.server 8080
Should you want to use an address other than the default 0.0.0.0
you can use --bind
Ex: python -m http.server 8080 --bind 127.0.0.1
will serve them at the address 127.0.0.1:8080
:)
Edit: Whether or not it truly was great lengths, I'll leave that to the reader
Also for your convenience here is a link to the docs https://docs.python.org/3/library/http.server.html
Here is a list of HTTP server in one line. I'm sure there is one that will fit your purposes/existing tooling.
Hereafter is a subset of the link, that contains in my opinion the most convenient ones.
Python:
python -m http.server 8000
Ruby:
ruby -run -ehttpd . -p8000
Node:
npm install -g http-server
http-server -p 8000
Php:
php -S 127.0.0.1:8000
One simple way to setup a static http site is to use darkhttpd
There is no package in ubuntu for that but the software is just one single source file that you can download with a tarball on the site or with git :
git clone https://unix4lyfe.org/git/darkhttpd
cd darkhttpd
Then run make
and you have your darkhttpd executable. (Place it in /usr/local/bin
to make it available to every user)
Run
./darkhttpd /path/to/wwwroot
or
./darkhttpd --help
to get help about the command
One can specify directory or port to use and many other options.