Set up your Apache server configuration file to use the Apache server with Unity Web builds.
Apache is an open source, cross-platform web server that you can use to serve applications you create with Unity Web.
For more information about Apache and how to install and use it, refer to the Apache documentation.
You can configure Web builds in Apache using one of the two methods:
Virtual host in httpd.conf
.
Virtual host in .htaccess
.
The recommended best practice is to configure a virtual host in Apache’s httpd.conf
, if you have access to that configuration.
httpd.conf
methodTo configure Web builds using the virtual host in httpd.conf
method, use the following code in your Apache server configuration:
<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
methodIf you’re unable to modify httpd.conf
, for example, due to unavailable admin rights to your web hosting, but your Apache supports .htaccess
, then you can configure .htaccess
in the following way:
# 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>
To improve loading performance of a gzip-compressed Web build with decompression fallback, add the following line to your code:
AddEncoding gzip .unityweb
To improve loading performance for Brotli-compressed builds with decompression fallback, add the following line of code to your configuration:
AddEncoding br .unityweb
If you created your build with Enable Native C/C++ Multithreading enabled in the Player settings, add the following code to your configuration file:
<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>
To allow CORS requests, add the following code to your configuration:
Header add Access-Control-Allow-Origin "*"
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.