2012-12-18 81 views
0

如何成为像CSS静态文件使用WERKZEUG和纯GEVENT静态文件渲染

蟒蛇..没有使用框架编写的应用程序WSGI ..

这是我的服务器..

from gevent import pywsgi 
from Index import application 

import os 
application = SharedDataMiddleware(application, { 
    '/hello/template/': os.path.join(os.getcwd(), 'template') 
}) 
print 'Serving on https://127.0.0.1:4000' 
server = pywsgi.WSGIServer(('0.0.0.0', 4000), application,spawn=10000) 

# to start the server asynchronously, call server.start() 
# we use blocking serve_forever() here because we have no other jobs 
server.serve_forever() 

模板是路径,如CSS和图像静态文件。但是这仅仅是服务于应用,而不是静态文件。有其中GEVENT提供静态文件的功能..?我没有找到的文档非常有用。

回答

1

直接从您的WSGI应用程序提供静态文件是浪费资源,CPU和内存,并且不会扩展。

对于公共静态文件,你应该配置前端Web服务器,直接为他们服务。

对于私有静态文件,您可以在WSGI应用程序中执行访问控制并构建响应标头,然后让前端Web服务器完成实际发送文件内容的繁重工作。看看X-SENDFILE(阿帕奇)或X阿塞尔 - 重定向(Nginx的)。