Dav*_*vid 1 apache webserver gzipstream mime-types webassembly
对于网络服务器来说非常新:
我正在尝试配置我的 Web 服务器以将 WebAssemblies (编辑:.wasm)作为应用程序/wasm 提供服务,据我所知,我所在的 Hostinger 主机使用 Apache。我也在使用gzip
(编辑#3 该网页是 Unity“WebGL”构建,并且 WebAssemblies 正在流式传输)
(编辑#2)
这是我的 public_html .htaccess 文件:
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat - [F,L]
### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###
### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###
### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS end ###
</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)
(编辑 #2 结束)
这是我在 Build 文件夹中的 .htaccess 文件:
# This configuration file should be uploaded to the server as "<Application Folder>/Build/.htaccess"
# This configuration has been tested with Unity 2020.1 builds, hosted on Apache/2.4
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
# The following lines are required for builds without decompression fallback, compressed with gzip
<IfModule mod_mime.c>
AddEncoding gzip .unityweb
AddEncoding gzip .wasm
AddType application/wasm .wasm
</IfModule>
<IfModule mod_mime.c>
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
</IfModule>
Run Code Online (Sandbox Code Playgroud)
根据控制台错误,我的“Build/WebGL Build.wasm.gz”文件似乎没有正确的 MIME 类型:
当然,问题是为什么“Build/WebGL Build.wasm.gz”不与 application/wasm MIME 类型一起提供?
看来我的第一个答案有缺陷,即使它仍然有效。这是不可接受的,因为它为尚未发现的问题以及与 Unity 和 WebXR Exporter 更新相关的新问题敞开了大门。
有人向我指出,某些文件的类型仍然错误(即“WebGL Framework.js.gz”应该是 JavaScript 类型,但实际上是 wasm 类型。)
所以,事实证明这里至少存在几个问题:
#1 扩展名之间需要空格。例如,如果您使用:
'AddType application/javascript .data.gz'
Run Code Online (Sandbox Code Playgroud)
该命令被忽略(我认为是因为它是语法错误。)但是如果您使用:
'AddType application/javascript .data .gz'
Run Code Online (Sandbox Code Playgroud)
它会起作用的。
#2 第二个问题似乎是旧的 Unity 文档。文档中的“.htaccess”似乎不再起作用。
我衷心感谢来自 WebXR Discord 服务器的 m2!m2 为我提供了 .htaccess 文件,它似乎工作得很好!
# This configuration file should be uploaded to the server as "<Application Folder>/Build/.htaccess"
# This configuration has been tested with Unity 2020.1 builds, hosted on Apache/2.4
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
# The following lines are required for builds without decompression fallback, compressed with gzip
<IfModule mod_mime.c>
<FilesMatch "[^.]+\.data.gz$">
Header set Content-Type "application/octet-stream"
Header set Content-Encoding "gzip"
</FilesMatch>
<FilesMatch "[^.]+\.js.gz$">
Header set Content-Type "application/javascript"
Header set Content-Encoding "gzip"
</FilesMatch>
<FilesMatch "[^.]+\.wasm.gz$">
Header set Content-Type "application/wasm"
Header set Content-Encoding "gzip"
</FilesMatch>
<FilesMatch "[^.]+\.gz$">
Header set Content-Encoding "gzip"
</FilesMatch>
<FilesMatch "[^.]+\.wasm$">
# Header set Content-Encoding "gzip"
Header set Content-Type "application/wasm"
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
(*** 编辑 #2 ***)
我发现我的服务器实际上是 LightSpeed Web 6.0.9 Enterprise,它是“Apache 替代品”,不确定这是否相关......
(*** 结束编辑 #2 ***)
现在,所有文件都有其正确的类型,如“网络”面板所示:
WebAssembly 流式处理现在正在运行的证据是不再出现 wasm 错误,并且页面加载速度提高了一倍。
我对服务器非常陌生,所以如果有人能证实我的分析,我将非常感激!
归档时间: |
|
查看次数: |
4587 次 |
最近记录: |