Run simple HTTP server on localhost

Sometimes you need to quickly run a simple HTTP server on your localhost to test or try something. If you already have Python installed, then you don’t need to go through installing a separate web service like Apache HTTPD or NGINX. Instead, cd to the directory where your .html files are located, then run the following command:

$ python -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...
127.0.0.1 - - [25/Mar/2020 15:03:44] "GET / HTTP/1.1" 200 -

If you had the following file index.html:

<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
    <div>My test page</div>
  </body>
</html>

It would look like this:

Leave a Reply

Your email address will not be published. Required fields are marked *