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?
Asked
Active
Viewed 5,663 times
13
-
https://docs.python.org/2/library/simplehttpserver.html – Validus Oculus Oct 28 '15 at 13:28
-
or you can use tornado library. http://stackoverflow.com/questions/21248222/how-can-tornado-serve-a-single-static-file-at-an-arbitrary-location – Validus Oculus Oct 28 '15 at 13:29
-
What sort of load are you expecting? – David Ehrmann Apr 22 '17 at 15:50
1 Answers
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
-
2I 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
-
2A 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