Why are static files served separately in webservers?

与世无争的帅哥 提交于 2021-02-08 08:50:46

问题


It seems like most web servers (Apache, Nginx, Lighthttpd) serve static files separately from the html files (different configuration). Why is this?

I'm trying to deploy my Django app with Apache and the deployment so far has been straightforward. In development the Django server served static files without me bothering to configure it. Why is it different in real webservers?


回答1:


It's a performance issue.

In a production setup you wouldn't want static content to be served through django. Serving static content through django involves a lot of overhead (loading the static file, processing python bytecode, passing through WSGI, etc) that is totally unnecessary for static content.

Web servers are extremely fast and efficient at serving static content themselves, so there is usually no reason to involve django / python in the request.

For a small site without a lot of load you could have django serve static content (you'd need to configure django to serve static content with DEBUG=False) and it would be relatively harmless, but it wouldn't be the 'right way' to do it.



来源:https://stackoverflow.com/questions/26105603/why-are-static-files-served-separately-in-webservers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!