uwsgi static

大坑

uwsgi默认在启动时扫描了static中设置的目录和文件,将所有路径读取了之后存储在哪,之后遇到请求会在这个存储的表中查找,这样导致后续新增的静态文件无法获取。

通过缓存配置缓存 --static-cache-paths 1,强制其每1秒去拿文件,这样可正常服务
(另需要创建出CACHE: cache2 = name=mycache,items=100)

配置

--check-static
在发送给app请求之前先查看静态资源

--check-static-docroot
在之前的服务器中设置了 DOCUMENT_ROOT 可以指示uwsgi来信任

--static-map mountpoint=path
使用这种方式把用户请求的路径映射到服务器中的路径中

--static-map2 /images=/var/www/img
/images/logo.png 会映射为 /var/www/img/images/logo.png 即保留了images

--route
route = /static/(.*).png static:/var/www/images/pngs/$1/highres.png
route = *.jpg static:/var/www/always_the_same_photo.jpg

--static-index index.html --static-index index.htm --static-index home.html
给对应文件路径的访问一个页面

--static-skip-ext .php --static-skip-ext .cgi --static-skip-ext .php4
不提供某些扩展名的文件

默认有LastModifed头部并参考If-Modified-Since头部
另可添加Expires头部

    # Expire an hour from now
    --static-expires-type text/html=3600
    # Expire an hour from the file's modification time
    --static-expires-type-mtime text/html=3600
    # Same as static-expires-type, but based on a regexp:
    --static-expires /var/www/static/foo*\.jpg 3600

GZIP,uwsgi可以在http https中使用gzip,最好提前给出压缩的版本

    static-gzip <regexp> checks for .gz variant for all of the requested files matching the specified regexp (the regexp is applied to the full filesystem path of the file)
    
    static-gzip-dir <dir>/static-gzip-prefix <prefix> checks for .gz variant for all of the files under the specified directory
    
    static-gzip-ext <ext>/static-gzip-suffix <suffix> check for .gz variant for all of the files with the specified extension/suffix
    
    static-gzip-all check for .gz variant for all requested static files

缓存,静态文件的映射,不要频繁地调用stat --static-cache-paths 30,或者直接把文件缓存到uwsgi中,可多次调用,但要传递完整的文件路径 --load-file-in-cache <filename>

offload

通过 offload-threads = 1 指定即可直接使用该功能

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • uWSGI参考资料(1.0版本的配置选项列表) 下面的内容包含了大部分uWSGI的配置选项,这些配置选项的列举没有...
    nine_9阅读 22,340评论 1 10
  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 2,079评论 0 9
  • Nginx 高性能的HTTP服务器程序,又是HTTP/IMAP/POP3协议的反向代理服务器 面对较高并发请求时,...
    SRE1阅读 6,688评论 2 5
  • I/O模型: 阻塞型、非阻塞型、复用型、信号驱动型、异步 同步/异步:关注消息通知机制 消息通知:同步:等待对方返...
    Net夜风阅读 2,032评论 0 1
  • docker file简介 Dockerfile 是由一个个的指令组成,是用于表示创建一个镜像文件的过程。 doc...
    sknfie阅读 679评论 0 0