Unity Web ビルドで Apache サーバーを使用するように、Apache サーバー設定ファイルを設定します。
Apache はオープンソースのクロスプラットフォームウェブサーバーで、Unity Web で作成するアプリケーションに使用できます。
Apache の詳細とインストールおよび使用方法については、Apache のドキュメント を参照してください。
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 .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
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) リクエストを許可するには、以下のコードを設定に追加します。
Header add Access-Control-Allow-Origin "*"