Web 服務器的全新功能:
我正在嘗試配置我的 Web 服務器來為 WebAssemblies(編輯:.wasm)提供應用程式/wasm 我在一個使用 Apache 的 Hostinger 主機上,據我所知。我也在使用 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
(結束編輯#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>
根據控制臺錯誤,我的“Build/WebGL Build.wasm.gz”檔案似乎沒有正確的 MIME 型別:

根據網路選項卡,它有一個 MIME 型別的文本/純文本:

所以當然問題是為什么“Build/WebGL Build.wasm.gz”沒有與 application/wasm MIME 型別一起提供?
uj5u.com熱心網友回復:
似乎我的第一個答案有缺陷,即使它仍然有效。這是不可接受的,因為它為尚未發現的問題以及與 Unity 和 WebXR 匯出器更新相關的新問題敞開了大門。
有人向我指出,有些檔案的型別仍然錯誤(即“WebGL Framework.js.gz”應該是 JavaScript 型別,但實際上是 wasm 型別。)
所以,事實證明這里至少有幾個問題:
#1 擴展名之間需要空格。例如,如果您使用:
'AddType application/javascript .data.gz'
該命令被忽略(我假設是因為它是一個語法錯誤。)但是,如果您使用:
'AddType application/javascript .data .gz'
它會起作用。
#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>
(*** 編輯 #2 ***)
我發現我的服務器實際上是 LightSpeed Web 6.0.9 Enterprise,它是“Apache 替代方案”,不確定這是否相關...
(*** 結束編輯 #2 ***)
Now all the files have their proper type as indicated by the Network panel:

Evidence that WebAssembly streaming is now working is that there are no longer wasm errors and the page loads TWICE as fast.
I am EXTREMELY new to servers so if anyone can confirm my analysis I would GREATLY appreciate it!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/357890.html
標籤:阿帕奇 网络服务器 哑剧类型 网络组装 gzipstream
