我不能设置nginx1.18(Ubuntu22.04作为服务器env,Chrome 104作为客户端)来处理.br或.gz文件。
我的前端代码绑定程序(Parcel 2)生成了.br和.gz index.html文件,但是当我试图访问https://mysite/index.html时,它抛出了404 Not found,而使用https://mysite/index.html.br,它只是试图下载Brotli文件。
我的假设是,Nginx应该将.br或.gz文件发送到Chrome,而Chrome <#>should会自动将其解压缩到常规html文件并显示网页。是对还是不对?
这是我的nginx.conf的一个摘录:
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
...
...
...
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
brotli on;
brotli_static on;
brotli_types
text/plain
text/css
text/xml
text/javascript
text/x-component
application/xml
application/xml+rss
application/javascript
application/json
application/atom+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-font-opentype
application/x-font-truetype
application/x-web-app-manifest+json
application/xhtml+xml
application/octet-stream
font/opentype
font/truetype
font/eot
font/otf
image/svg+xml
image/x-icon
image/vnd.microsoft.icon
image/bmp;这是服务器conf:
...
location ~* \.(js|jpg|png|jpg|jpeg|git|ico|css|eot|woff|woff2|svg|webmanifest)$ {
root /var/www/main;
try_files $uri $uri/ /webgl$uri =404;
}
location / {
root /var/www/main/webgl;
try_files $uri $uri/ =404;
}
...我要做什么?谢谢!
发布于 2022-08-21 17:55:17
如果服务器上没有未压缩版本,则当客户端请求文件的未压缩版本时,需要使用模块使nginx解压缩文件。
gzip_static只告诉nginx将.gz版本发送给那些告诉他们接受gzip编码响应的客户端。
发布于 2022-08-21 20:41:48
看起来,如果没有文件夹中的index.html.br版本,Nginx就无法处理index.html和index.html.gz。
解决方案:只需在没有压缩的情况下将文件添加到您的文件夹中,Nginx就会发送压缩文件(当然,如果浏览器将在请求中发送适当的accept-encoding属性(例如,accept-encoding: gzip, deflate, br)。
https://serverfault.com/questions/1108728
复制相似问题