官方文檔:https://docs.unity3d.com/Manual/webgl-deploying.html
問題:You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression.
官方只給了ISS服務器和Apache服務器,關於nginx服務器沒有說。
一、本地搭建nginx服務器:
學習文檔:
https://www.jianshu.com/p/ceb2cc9ae429
1)出錯解決:nginx: [error] CreateFile() "C:\nginx-1.17.1\nginx-1.17.1/logs/nginx.pid" failed (2: The system cannot find the file specified)
原因:nginx服務器沒有啓動,就reload必然失敗。
2)打出webgl項目:拷貝到html文件夾裏面
我修改了unity到處的index.html爲index_unity.html, reload就可以了
二、解決unityweb格式問題:
參考:https://forum.unity.com/threads/configure-nginx-to-serve-unityweb-with-gzip-header.524529/
解決方法:打開C:\nginx-1.17.1\nginx-1.17.1\conf 目錄下的nginx.conf文件,
插入代碼;
location ~ .+\.unityweb$ {
add_header Content-Encoding gzip;
}
然後重啓
去遊覽器 ctrl+shift+del刪除緩存,重啓遊覽器,網址輸入http://localhost/index_unity.html
就可以本地運行webgl項目。