WebGL☀️Unity WebGL适配到各平台的教程

本文档详细介绍了如何解决Unity WebGL在Apache服务器上遇到的“Content-Type”配置错误和“Unable to parse”问题。主要内容包括修改httpd.conf以启用.htaccess和加载mod_rewrite模块,以及创建正确配置的.htaccess文件来处理WebGL内容的Gzip压缩。通过这些步骤,可以确保Unity WebGL项目在不同平台上顺利运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述


🟥 HTTP Response Header “Content-Type”

你应该用的Disable压缩打包。加载WebGL后,报错代码如下:

HTTP Response Header “Content-Type” configured incorrectly on the server for file Build/WebGLRoaming.wasm.gz , should be “application/wasm”. Startup time performance will suffer.

在这里插入图片描述

解决方法跟下面的 《Unable to parse Build/WebGLRoaming.framework.js.gz!》相同。



🟧 Unable to parse Build/WebGLRoaming.framework.js.gz!

你应该使用的是Gzip压缩打包。报错代码如下:

This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header “Content-Encoding: gzip” present. Check browser Console and Devtools Network tab to debug.

在这里插入图片描述



1️⃣ Apache启用.htaccess

🚩 修改httpd.conf权限

搜索httpd.conf,找到如下代码:

Options FollowSymLinks 
AllowOverride None 

修改为 :

Options FollowSymLinks 
AllowOverride All 

🚩 加载 mod_rewrite模块

搜索httpd.conf,去掉下面的注释

LoadModule rewrite_module modules/mod_rewrite.so 



2️⃣ 增加 .htaccess 文件

这时需要你在你的网页根目录下(即index.html同级位置),添加 .htaccess 文件,文件内容如下:

# This configuration file should be uploaded to the server as "<Application Folder>/Build/.htaccess"
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
<IfModule mod_mime.c>

# The following lines are required for builds without decompression fallback, compressed with gzip
RemoveType .gz
AddEncoding gzip .gz
AddType application/octet-stream .data.gz
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz

# The following lines are required for builds without decompression fallback, compressed with Brotli
RemoveType .br
RemoveLanguage .br
AddEncoding br .br
AddType application/octet-stream .data.br
AddType application/wasm .wasm.br
AddType application/javascript .js.br
AddType application/octet-stream .symbols.json.br
AddType application/wasm .wasm

# The following line improves loading performance for uncompressed builds
AddType application/wasm .wasm

# Uncomment the following line to improve loading performance for gzip-compressed builds with decompression fallback
# AddEncoding gzip .unityweb

# Uncomment the following line to improve loading performance for brotli-compressed builds with decompression fallback
# AddEncoding br .unityweb

</IfModule>





大家还有什么问题,欢迎在下方留言!


在这里插入图片描述
如果你有 技术的问题 项目开发

都可以加下方联系方式

和我聊一聊你的故事🧡

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值