无法在 runcloud nginx 服务器上解决 wasm/unityweb 错误

问题描述

网站托管在 Ubuntu 18 服务器上 由 runcloud.io 管理 PHP 7.4 runcloud 的 Nginx 认配置。

我们在临时服务器上部署了一个 webgl 构建,并且无法在不引发控制台错误的情况下加载它:

You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression.

wasm streaming compile Failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

falling back to ArrayBuffer instantiation

我创建了以下 Nginx 配置文件

location ~ .(wasm)$ {
    add_header content-encoding gzip;
    add_header Content-Type application/wasm;
}

location ~ .(unityweb)$ {
    add_header content-encoding gzip;
    add_header Content-Type application/octet-stream;
}

location ~ .(data.unityweb)$ {
    add_header content-encoding gzip;
    add_header Content-Type application/octet-stream;
}

location ~ .(wasm.framework.unityweb)$ {
    add_header content-encoding gzip;
    add_header Content-Type application/octet-stream;
}

include /etc/Nginx-rc/mime.types;
types {
    application/wasm wasm;
}
default_type application/octet-stream;
    
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types application/wasm application/octet-stream text/plain text/css text/xml application/json application/javascript application/xml+RSS application/atom+xml image/svg+xml;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)