包含此页的版本:
不含此页的版本:
设置 Apache 服务器配置文件以将 Apache 服务器与 Unity Web 版本一起使用。
Apache 是一个开源的跨平台 Web 服务器,可用于为使用 Unity Web 创建的应用程序提供服务。
有关 Apache 以及如何安装和使用它的更多信息,请参阅 Apache 文档。
您可以使用以下两种方法之一在 Apache 中配置 Web 构建:
虚拟主机httpd.conf.
虚拟主机.htaccess.
推荐的最佳实践是在 Apache 的httpd.conf,如果您有权访问该配置。
httpd.conf方法要使用httpd.conf方法,请在 Apache 服务器配置中使用以下代码:
<Directory /var/www/html/root/path/to/your/unity/content/>
<IfModule mod_mime.c>
RemoveType .gz
AddEncoding gzip .gz
# The correct MIME type for .data.gz would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it is preferable to use MIME Type application/gzip instead.
#AddType application/octet-stream .data.gz
AddType application/gzip .data.gz
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz
RemoveType .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
# Insert additional code here
</IfModule>
</Directory>
.htaccess方法如果您无法修改httpd.conf,例如,由于您的网络托管的管理员权限不可用,但您的 Apache 支持.htaccess,则可以配置.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/gzip .data.gz # The correct MIME type here would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it's preferable to use MIME Type application/gzip instead.
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
# The following line improves loading performance for uncompressed builds
AddType application/wasm .wasm
# Insert additional code here
</IfModule>
要提高具有解压缩回退的 gzip 压缩 Web 构建的加载性能,请在代码中添加以下行:
AddEncoding gzip .unityweb
要提高具有解压缩回退功能的 Brotli 压缩版本的加载性能,请将以下代码行添加到您的配置中:
AddEncoding br .unityweb
如果您在播放器设置中激活了 启用原生 C/C++ 多线程时构建了项目,则需要设置特定的服务器标头。这些标头包括跨域打开器策略 (COOP)、跨域嵌入式策略 (COEP) 和跨域资源策略 (CORP)。
将此代码添加到配置文件中:
<FilesMatch "\.(htm|html|js|js.gz|js.br)$">
Header add Cross-Origin-Opener-Policy "same-origin"
Header add Cross-Origin-Embedder-Policy "require-corp"
Header add Cross-Origin-Resource-Policy "cross-origin"
</FilesMatch>
若要允许 CORS 请求,请将以下代码添加到配置中:lang-apacheconf
Header add Access-Control-Allow-Origin "*"