微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

DDEV无法在Nginx中处理SVGZ文件

如何解决DDEV无法在Nginx中处理SVGZ文件

我在Typo3 v9环境中使用DDEV v1.15.3。我根据《快速指南》使用 ddev config --project-type = typo3 --PHP-version 7.3 --docroot = public --create-docroot = true 创建了Typo3环境。到目前为止,一切正常,但没有显示SVGZ文件

在fileadmin后端上传的svgz文件不会在浏览器中显示-像https://ddev-typo3v9.ddev.site:444/fileadmin/user_upload/meinen_jmd_vor_ort_finden.svgz。我收到以下错误消息:

页面包含以下错误: 第1行第1行出现错误:编码错误 以下是直到第一个错误页面呈现。

要在Nginx容器中启用gzip压缩,我将以下行添加文件 .ddev / Nginx_full / Nginx-site.conf

# Compression
gzip on;
gzip_proxied        any;
gzip_comp_level     6; # Level of compression
gzip_http_version   1.1;
gzip_min_length     1100;
gzip_buffers        16 8k;

gzip_types
 text/plain
 text/css
 text/xml
 application/x-javascript
 application/atom+xml
 text/mathml
 text/vnd.sun.j2me.app-descriptor
 text/vnd.wap.wml
 text/x-component
 text/javascript
 application/javascript
 application/json
 application/xml
 application/RSS+xml
 font/truetype
 font/opentype
 application/vnd.ms-fontobject
 image/svg+xml svg svgz;

gzip_static on;
gunzip on;
gzip_proxied        expired no-cache no-store private auth;
gzip_disable        "MSIE [1-6] \."; # disable for IE < 6

# Add a vary header for downstream proxies to avoid sending
# cached gzipped files to IE6
gzip_vary on;

# ### Compression ###

# For CSS with compression
location ~* "\.css(\.|\.\d{10}\.)gzip$" {
        rewrite ^(.+css)\.(\d+\.)gzip$ /$1.gzip;
        add_header  content-encoding gzip;
        add_header  vary Accept-Encoding;
        add_header Access-Control-Allow-Origin *;
        gzip off;
        types { text/css gzip; }
        expires max;
        log_not_found off;
}

# For JavaScript with compression
location ~* "\.js(\.|\.\d{10}\.)gzip$" {
        rewrite ^(.+js)\.(\d+\.)gzip$ /$1.gzip;
        add_header  content-encoding gzip;
        add_header  vary Accept-Encoding;
        gzip off;
        default_type application/javascript;
        expires max;
        log_not_found off;
}

# Compression for SVGZ
location ~* \.svgz$ {
       add_header content-encoding gzip;
}

当我使用 ddev ssh 连接到Docker容器时,Nginx配置也包含上述行。

感谢您的帮助。

最好的问候

-杰拉尔德

解决方法

您需要在.ddev / nginx_full / nginx-site.conf中添加的内容

location ~ \.svgz$ { add_header Content-Encoding gzip; }

我将我的nginx-site.conf文件放在https://gist.github.com/rfay/5071ff19237ee7b83442cd8ad0311459

我使用了example.svgz中的文件https://www.online-convert.com/file-format/svgz

This nginx issue解释了怎么做。

这是我之后看到的1)使用文件管理器上传example.svgz,然后2)单击“显示”图标。

enter image description here

如果您认为添加默认的nginx配置很重要,请通过https://github.com/drud/ddev/issues

打开问题或PR

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。