问题
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