Unity exports the WebGL project and deploys a local web server

WebGL packaging

settings modification

在Build Settings->PlayerSettings->Other Settings->Rendering

  • Set Color Space to Gamma

  • Set Lightmap Encoding to NormalQuality

在Build Settings->PlayerSettings->Publishing Settings

  • Check Decompression Fallback

 

Pack

After completing the configuration modification, you can directly select Build And Run on the Build interface. After the build is completed, it will be automatically deployed by Unity, and the webpage can be opened normally.

 

If Build is selected, export the WebGL project. Click index.html directly locally, and the following error will appear. A web server needs to be deployed for normal access. The following will deploy a local nginx server to solve this problem

 

Deploy Nginx

Install Nginx

Windows side

Go to the official website of niginx http://nginx.org/en/download.html

Download the stable version

 

After decompressing the downloaded zip, double-click nginx.exe to run

 

Mac side

Enter the following command on the command line to install ngnix

 
 

brew install ngnix

After the installation is complete, you can see the following output log

 

Where /opt/homebrew/etc/nginx/nginx.conf is where the nginx configuration is located

Change setting

Open conf/niginx.conf, change the port number and server_name to an unoccupied port number and the ip address of the machine

 server {
        #这里填一个未被占用的端口
        listen       8080;
        #这里填本机ip
        server_name  10.244.115.20;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        
        location / {
            #这里填unity导出的webgl工程地址
            root   "D:\UnityProjects\DiceGameWeb";
            index  index.html index.htm;
        }
}

reload configuration

After modifying the configuration, you need to reload the nginx configuration and run it in the directory where nginx.exe is located

./nginx -s reload

Run the webgl project

Finally, splice the local machine address and port number filled in the configuration together to visit, http://10.244.115.20:8080/index.html

can run normally

 

problem solving

Unable to parse Build/DiceGameWeb.framework.js.br! If using custom web server, verify that web server is sending .br files with HTTP Response Header "Content-Encoding: br". Brotli compression may not be supported over HTTP connections. Migrate your server to use HTTPS.

BuildSetting->PlayerSettings->

Executing nginx command error: nginx: [error] open() "/opt/homebrew/var/run/nginx.pid" failed (2: No such file or directory)

The reason is that the pid of nginx is lost, so xx/nginx.conf after the command of nginx -c /opt/homebrew/etc/nginx/nginx.conf is the actual storage address of nginx.config

Guess you like

Origin blog.csdn.net/shaobing32/article/details/129089513