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?

Matt
  • 27,170
  • 6
  • 80
  • 74
zxz
  • 709
  • 1
  • 8
  • 19

1 Answers1

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
Leo
  • 1,102
  • 2
  • 11
  • 18
  • 2
    `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 – JamesTheAwesomeDude Jul 24 '20 at 22:17
  • 2
    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 Kareem Dec 23 '20 at 18:38
  • 2
    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. – Antoine Claval Mar 31 '21 at 00:33