美文网首页
uwsgi static

uwsgi static

作者: xncode | 来源:发表于2023-06-04 16:14 被阅读0次

大坑

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 static

      本文链接:https://www.haomeiwen.com/subject/jclqtltx.html