Grimoire-
Command
.es

GNU+Linux command memo

Python local HTTP server starting fast

Lancer rapidement un serveur web local.

$ python -m http.server --bind 127.0.0.1 8000

Details :

$ python -m http.server \ (1)
		--bind 127.0.0.1 \ (2)
			8000 (3)
Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...
1 This command starts a web server on your machine, serving by default the content of the current folder. It’s now needed by Firefox to load the CSS of a local HTML file.
2 The command starts instantly, but if you omit the --bind 127.0.0.1 option, it binds to all local IPs available and it takes 10s on a modern and strong configuration.
3 You can omit the 8000 port number (it’s the default), but you’ll need to change it if you want to open another server at the same time.
I’ve been reported normal / fast server launch time even with default settings on Mastodon. I also read other complaints on the net about this slow launch. The mystery persists.
https://docs.python.org/3/library/http.server.html : By default, the server binds itself to all interfaces. The option -b/--bind specifies a specific address to which it should bind. Both IPv4 and IPv6 addresses are supported. For example, the following command causes the server to bind to localhost only: python -m http.server --bind 127.0.0.1