HTTP Server Setup with a Single Command Line

Written by @alexxgg, 19 May 2021
Article was migrated from WordPress to Vanilla in March 2022

image

This is a guest post by forum user @alexxgg,

Hi there!

These days when the internet shares things in milliseconds, who of you have needed to share a file quickly? I bet some of you remember at least one time one of those cases.

As you probably know, in terms of web servers, we can share files with popular software like Apache, Nginx, and Lighttpd but this software need basic configuration, also they consume server resources as long as they’re active.

What if you could set up a basic HTTP web server without installing Apache, Nginx, or Lighttpd? Well, that’s sounds kind of impossible, and even more unbelievable is that you can kill it with Ctrl^C. Thanks to Python3 we can do that with its HTTP server module.

This module will deploy an HTTP server in any directory of the server, even in the root directory and that sounds ridiculously dangerous, fortunately, the default port of this HTTP server isn’t 80. Instead, it will use port: 8000 but you can assign a custom port, very convenient for NAT environment instances.

Now you can deploy a basic HTTP server -in the current directory with the default port- by typing this single command line:

python3 -m http.server

Starting HTTP Server

Killing HTTP Server

HTTP Server as Shown in Browser

You can change the default port (example port: 32085) and specify a directory (example directory: /tmp/) with:

python3 -m http.sever 32085 --directory /tmp/

More information about Python3 httpserver module is available here

Also, there is a github page here

Note: of course, you will need to install Python3 in order to use these post example command lines.
Leave a comment to let me know any questions or suggestions.

Comments

Sign In or Register to comment.