Simple HTTP server with 208 redirect in Python

Simple HTTP server with 208 redirect in Python

In today’s post, I will show you how to start a simple web server that will be accessible within your network, and when users enter its address, they will be redirected to an external address.

I created my web server on Debian, and it’s written in Python. I used the Flask framework. The server will perform a redirection to the specified external address.

First, we need to install Python (if it’s not already installed).

The next step is to install Flask, and you can also install any required libraries (for example, if you decide to use JWT):

At this point, we have everything we need to create the HTTP server script. So let’s start creating the server code.

Now, you need to save the script with a name, for example, webserver.py, and give it the appropriate permissions:

Now, you can run the script:

This code creates a Flask server that listens on port 80. When it receives a GET request at the /start path, it performs a 308 redirection to the specified address. You can customize the port and URL address to suit your needs.

After running the script, you can access the server’s IP address on the specified port, for example, in my case, it would be http://192.168.0.5/start using a web browser. Upon entering this address, you will be redirected to the page specified in the script, in this case, https://cybermonitor.pl.

We still need to address automatic server startup so that it’s available after a restart, but I will show you that in the next post.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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