13

I want to serve static files with Python. Is the Python 3 http.server suitable for use in production? If not, why not? And what are my alternatives?

3

1 Answer 1

4

Quoting documentation https://docs.python.org/3/library/http.server.html#module-http.server

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

First of all you don't need python at all to serve static files. Just use a real HTTP Server like Apache or NGinx. If you want a quick solution just look for a docker container with a pre-configured image suitable for your needs. Here is the NGinx. Definitely docker is a must have tool that you will not regret to learn.

$ docker run --name mysite-nginx -v /mysite:/usr/share/nginx/html:ro -p 80:80 -d nginx
Sign up to request clarification or add additional context in comments.

3 Comments

you don't need python at all to serve static files. Just use a real HTTP Server like Apache -- I arrived at this question to see if it's possible to "just serve a folder" without invoking the behemoth that is Apache... if you don't need any features
I honestly just want to know if I can run a very VERY simple http api (single get single post command thats it) that only I will ever actually use. And I want this server to easilly be started and stopped in another python script, SimpleHTTPServer seemed like the answer but the warning in the documentation makes me quite concerned that it's a huge vulnerability risk to use (since the port will be exposed to the internet obviously). and as the other comment says, I really don't want to invoke a BEHEMOTH like apache for such a small tiny scale personal use.
A docker wrapped nginx is light to operate. You can also benefit from some auto-restart, log-rotate and the like. SimpleHttpServer will do the trick, but you will end up ssh-ing into that box often to babysit it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.