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?
-
docs.python.org/2/library/simplehttpserver.htmlValidus Oculus– Validus Oculus2015-10-28 13:28:03 +00:00Commented Oct 28, 2015 at 13:28
-
or you can use tornado library. stackoverflow.com/questions/21248222/…Validus Oculus– Validus Oculus2015-10-28 13:29:07 +00:00Commented Oct 28, 2015 at 13:29
-
What sort of load are you expecting?David Ehrmann– David Ehrmann2017-04-22 15:50:10 +00:00Commented Apr 22, 2017 at 15:50
Add a comment
|
1 Answer
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
3 Comments
JamesTheAwesomeDude
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 featuresA Kareem
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.
Antoine Claval
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.