Unable to resolve wasm / unityweb errors un runcloud nginx server

1.7k views Asked by At

Site is hosted on a Ubuntu 18 server Managed by runcloud.io PHP 7.4 runcloud's nginx default config.

We have a webgl build deployed on our staging server, and unable to get it to load without throwing console errors:

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

I have create the following nginx config file:

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;
1

There are 1 answers

0
mmerle On

I managed to host a Unity/WelGL app on a nginx server changing parameters of my Unity "Project Settings":

In "Player" tab, open "Publishing Settings":

  • Compression Format: Gzip
  • Decompression Fallback: ON

Found the solution on the Unity WebGL documentation. This is avoiding the error message.

I did not had to change my nginx configuration files.