How to run a temp webserver

This is to test Firewalls , Loadbalancer etc… quick and easy for labbing

This was taking from :   https://linuxconfig.org/running-a-simple-http-web-server-with-one-terminal-command-and-pythonConfigure simple web server in Linux

Configure simple web server in Linux

The purpose of this tutorial is to host a simple web server using only Python on a Linux system. This produces a very lightweight web server and works well to host a microservice, a browser-based file manager, or to test a website without deploying a full web server such as Apache or NGINX.

Follow along with the steps below to learn how to use Python to set up a simple web server on any Linux distribution. We will be using Ubuntu Linux in our example, and the version of Ubuntu will not matter as long as you are using Python 2 or Python 3 (recommended).

In this tutorial you will learn:

  • How to install Python 3 on major Linux distros
  • How to host a web server using Python 3 or Python 2
  • How to access the Python hosted web server in browser
Configure simple web server in Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software Python 3
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to install Python 3 on major Linux distros


The only prerequisite to follow this guide is that you have Python 3 installed on your system. Python 2 will also work, but will require a slightly different command. We will cover both below. But first, use the instructions below to install Python on your Linux system.You can use the appropriate command below to install Python 3 with your system’s package manager.

To install Python 3 on UbuntuDebian, and Linux Mint:

$ sudo apt install python3

To install Python 3 on FedoraCentOSAlmaLinux, and Red Hat:

$ sudo dnf install python3

To install Python 3 on Arch Linux and Manjaro:

$ sudo pacman -S python3

Configure simple web server in Linux step by step instructions

To start a web server using Python 3, use the following command. With this syntax, our web server will be running on IP address 127.0.0.1 and port 9000. You can change this to anything you want, or omit the options entirely to have Python be hosted on the default IP and port.

$ python3 -m http.server --bind 127.0.0.1 9000

The Python 2 equivalent command would be:

$ python -m SimpleHTTPServer 9000

You should see confirmation in your terminal window that Python is now serving an HTTP server on the IP and port you configured.

Hosting a simple web server in Python on Linux
Hosting a simple web server in Python on Linux

Now you can open up a browser and navigate to the address you configured, which is http://127.0.0.1:9000 in our case.

Navigating to our Python hosted web server in Firefox
Navigating to our Python hosted web server in Firefox

As you can see, by default the website just displays our home directory and all of the files inside of it. We can now use this as a file browser. This might prove useful if you want to download some of these files from another system on your local area network.

Of course, you can also move a Python file into this directory and access it through the web browser.

 

Leave a Comment