Two Ways To Host Unity WebGL Locally

Unity logo

Introduction

Working with WebGL can be tricky, and a simple thing that’s overlooked is hosting a WebGL app locally for debugging. I’ll share 2 easy ways to host a WebGL build locally below.

Unity Build and Run dialog for WebGL

1. Unity’s Build-and-Run

  • This one is the easiest.
  • All you have to do is go to Build Settings -> WebGL -> Build and Run.
    • Unity will host a temporary local server for your app once it builds!

Unity Build and Run settings

2. Using Python

  • Install Python

  • Change directory to where your Unity WebGL build resides

  • Run the following command:

    python3 -m http.server 9090
    • This will host a local HTTP server on port 9090

P.S. I tried getting this working using Docker, but it wasn’t as easy as copying the files into an nginx container.