Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up simple SAFE http server in Python3

I want to set up very simple http server whith replaces few keywords in single html file and send it in repspond to request to clients. Python's http.server looks good for me but in documentation I found:

Warning http.server is not recommended for production. It only implements basic security checks.

and in source code:

SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL -- it may execute arbitrary Python code or external programs.

Do you know any way to create safty http server which ports could be foreword via firewall to internet?

like image 618
domino_pl Avatar asked Jan 11 '19 09:01

domino_pl


People also ask

How do I start simple HTTP server in Python3?

Python Simple HTTP Server Now, use shift+right click . Your will find option to open command prompt in that directory. Just click on that and open command prompt there. However, if you are using Ubuntu, just right click into that directory and open terminal.

Is python HTTP server safe?

Since Python Simple HTTP Server is running solely on Python code (as far as I know, again.) you got nothing to worry about. (Unless you are also logging HTTP requests using different applications or methods.)

What tool can you use to create a simple HTTP server with python?

Python3 SimpleHTTPServer is a built-in HTTP server in which you don't have to install and configure anything. Therefore, SimpleHTTPServer is a very convenient tool. You can use the Python SimpleHTTPServer to turn any directory into a simple HTTP web server.


1 Answers

If its a Python web application, there are several options available for HTTP servers in Python. Among the safe one's are Gunicorn, Nginx WSGI, mod_wsgi. A list is available here. I'll take mod_wsgi as an example. The official documentation states there are two ways to install this package & both are safe for production deployments:

The package can be installed in two different ways depending on your requirements. The first is as a traditional Apache module installed into an existing Apache installation.The second way of installing mod_wsgi is to install it from PyPi using the Python pip command. This builds and installs mod_wsgi into your Python installation or virtual environment. Both installation types are suitable for production deployments.

According to the docs, the best option is to use: Apache + mod_wsgi + docker.

For mod_wsgi, you will need to configure Apache 2.4 and both Python 2 & 3 are supported. The requirements are stated here.

The Apache web server is widely used in production applications. The Apache HTTP Server Project is among the oldest and well maintained for 20 years. You can read more about it here. As for implementing security, you should read this answer.

like image 53
amanb Avatar answered Oct 02 '22 05:10

amanb