为什么静态文件在Web服务器中单独提供? [英] Why are static files served separately in webservers?

查看:355
本文介绍了为什么静态文件在Web服务器中单独提供?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎大多数Web服务器(Apache,Nginx,Lighthttpd)都将静态文件与html文件分开提供(不同的配置).为什么会这样?

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

我正在尝试使用Apache部署Django应用,到目前为止,部署一直很简单.在开发中,Django服务器无需静态配置即可提供静态文件.为什么在实际的网络服务器中会有所不同?

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?

推荐答案

这是性能问题.

在生产设置中,您不希望通过Django提供静态内容.通过django提供静态内容会涉及很多开销(加载静态文件,处理python字节码,通过WSGI传递等等),对于静态内容来说完全没有必要.

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服务器本身可以非常快速高效地提供静态内容,因此通常没有理由在请求中涉及django/python.

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.

对于一个没有很多负载的小型站点,您可以让django提供静态内容(您需要配置django来使用 DEBUG = False 提供静态内容),这相对来说是无害的,但这不是做到这一点的正确方法".

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.

这篇关于为什么静态文件在Web服务器中单独提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆