ドキュメント

Unity Engine

Unity Engine

Web ビルド用の Apache サーバー設定

Instructions on how to set up your Apache server for your Web build.
読み終わるまでの所要時間 6 分最終更新 1ヶ月前

Unity Web ビルドで Apache サーバーを使用するように、Apache サーバー設定ファイルを設定します。
Apache はオープンソースのクロスプラットフォームウェブサーバーで、Unity Web で作成するアプリケーションに使用できます。
Apache の詳細とインストールおよび使用方法については、Apache のドキュメント を参照してください。

Apache Web ビルド方法の選択

Apache で Web ビルドを設定するには、以下の 2 つの方法のいずれかを使用します。
  • httpd.conf
    の仮想ホスト
  • .htaccess
    の仮想ホスト
推奨されるベストプラクティスは、Apache の
httpd.conf
の仮想ホストを設定することです (その設定にアクセスできる場合)。

httpd.conf の仮想ホストによる方法の使用

httpd.conf
の仮想ホストによる方法を使用して Web ビルドを設定するには、Apache サーバー設定で以下のコードを使用します。
<Directory /var/www/html/root/path/to/your/unity/content/><IfModule mod_mime.c>RemoveType .gzAddEncoding 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.##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.gzAddType application/gzip .data.gzAddType application/wasm .wasm.gzAddType application/javascript .js.gzAddType application/octet-stream .symbols.json.gzRemoveType .brAddEncoding br .brAddType application/octet-stream .data.brAddType application/wasm .wasm.brAddType application/javascript .js.brAddType application/octet-stream .symbols.json.br# Insert additional code here##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.##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##the-following-lines-are-required-for-builds-without-decompression-fallback-compressed-with-gzipRemoveType .gzAddEncoding gzip .gzAddType 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.gzAddType application/javascript .js.gzAddType application/octet-stream .symbols.json.gz# The following lines are required for builds without decompression fallback, compressed with Brotli##the-following-lines-are-required-for-builds-without-decompression-fallback-compressed-with-brotliRemoveType .brRemoveLanguage .brAddEncoding br .brAddType application/octet-stream .data.brAddType application/wasm .wasm.brAddType application/javascript .js.brAddType application/octet-stream .symbols.json.br# The following line improves loading performance for uncompressed builds##the-following-line-improves-loading-performance-for-uncompressed-buildsAddType application/wasm .wasm# Insert additional code here##insert-additional-code-here</IfModule>

gzip 圧縮されたビルドのパフォーマンス向上

解凍フォールバックを使用して gzip 圧縮された Web ビルドのロードパフォーマンスを向上させるには、コードに以下の行を追加します。
AddEncoding gzip .unityweb

解凍フォールバックによる Brotli 圧縮されたビルドのパフォーマンス向上

解凍フォールバックを使用して Brotli 圧縮されたビルドのロードパフォーマンスを向上させるには、設定に以下のコード行を追加します。
AddEncoding br .unityweb

Enable native C/C++ multithreading

Player 設定 で Enable Native C/C++ Multithreading を有効にしてビルドを作成した場合は、以下のコードを設定ファイルに追加します。
<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) リクエストの許可

オリジン間リソース共有 (CORS) リクエストを許可するには、以下のコードを設定に追加します。
Header add Access-Control-Allow-Origin "*"

追加リソース