Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

AWS for WebGL Hosting

Discussion in 'WebGL' started by ironfiftynine, Apr 21, 2015.

  1. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    56
    Good day. I tried hosting my unity webgl protoype game on some free hosting sites but I've encountered some problems, enough for me to consider using a paid hosting service instead. With this, I'm looking at Amazon Web Services. Has anyone tried hosting a WebGL build in AWS? If yes, how was setup process and performance of the build? Do you have any better recommendations over AWS? My apologies that I'm asking several questions in one post. I'm trying to be specific as possible. Thanks in advance. :)
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    It might be worth looking at basic shared VPS hosting, it will probably work out cheaper than AWS. The cheapest ones won't handle a lot of traffic but should be OK for testing and development.

    Basically though, anything that lets you install your own server software should not present any problems. The places you'll have trouble with are the ones who run specific server software on shared hosting and don't give individual clients access to the config files.
     
    ironfiftynine likes this.
  3. Andrejus

    Andrejus

    Joined:
    Mar 2, 2015
    Posts:
    10
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,461
    Our game is hosted on Amazon S3 (part of AWS) without any issues.

    The only thing is that it doesn't work with the .htaccess file, so we have to rename a few files and set their content type to gzip.
     
  5. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    56
    Thanks for your inputs. Just to add, part of the issues that I encountered are:
    • Upload timeout in FTP for large files (I tried 70 MB which I think is still fairly small). I used FireZilla and SmartFTP but both of them resulted to an error, so when I tested the build by accessing the actual external URL of the html page, the javascript threw an error since the file was not completely transferred. I've already searched for guides and forum posts and based on what I've read so far, it's either the server or the router that I'm using. I think it's the former...
    • When I uploaded the file successfully (at least that's what I think it is when FireFTP returned a success message after upload with no errors), the javascript error still occurs. My hunch is that the server needs to be refreshed for the updated file contents. Is my hypothesis correct?
    Will I still encounter the same problems when I use AWS, VPS, or other paid hosting services?

    @Andrejus I was actually using hostinger in the Philippine domain, but I can't successfully upload the 70 MB file due t timeout when I used the mentioned FTP clients. Is there a configuration that I need to adjust? I can't find such setting in the cPanel. Thanks.

    @liortal I see, so it will still has some tweaking to do. That's what I'm trying to avoid given that I'm not that much acquainted with server setups, but if the service is that reliable, then I'm willing to tinker. Thanks!
     
  6. sokki

    sokki

    Joined:
    Jan 31, 2015
    Posts:
    164
    I don't know what is the solution on that, but I know that some servers needs to be recoded (probably by adding some html file or sorta) in order to accept and stream webgl games. Good luck :)
     
  7. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    @liortal, can you elaborate on what changes you make to enable hosting on s3?
     
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,461
    The only thing we did was to enable compression support. S3 does not use the .htaccess file, so we had to manually do the steps that this file does:
    • Rename Compressed folder -> Release
    • Rename all *.*gz files to drop the gz extension, eg: blabla.datagz renamed to blabla.data
    • Mark all file as content-encoding: gzip after uploading to S3.
     
    ironfiftynine likes this.
  9. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    That's very helpful - thank you!
     
    liortal likes this.
  10. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    249
    @liortal
    Followed all the steps except the last one.
    Could not make out how to set the content encoding.
    Please refer the image attached. I modified the metadata property and added content-encoding. Is it correct ?
    I could not get the game running with this setting
     

    Attached Files:

    • gzip.PNG
      gzip.PNG
      File size:
      19 KB
      Views:
      1,431
  11. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,461
    Yes thats how we do it (maybe we dont set the first property though)
     
  12. airsickness

    airsickness

    Joined:
    Sep 3, 2014
    Posts:
    4
    As @liortal said, we renamed by killing the gz because during the async download process its looking for the .mem file and if its memgz it bails out.
     
  13. Charles-Van-Norman

    Charles-Van-Norman

    Joined:
    Aug 10, 2010
    Posts:
    86
    Hello everyone -- I would like to help out this thread by sharing what worked for me to deploy WebGL through AWS S3. You cannot do this by simply copying folders over if you want to deliver /Compressed/ content, because .htaccess handles rerouting the requests for /Release/ to /Compressed/, and S3 does not allow .htaccess. Here is what I did that works.

    Deploy /compressed/ webgl build to S3
    1. Build WebGL project from Unity
    2. Delete /Release/ folder
    3. Remove gz from the end of each filename in /Compressed/ folder
    4. Rename /Compressed/ to /Release/ folder.
    5. Upload your entire /WebGLgame/ folder to S3. Make sure you set permission to publicly accessible.
    6. Modify the headers of each file in /Release/ by adding "Content-Encoding":"gzip" through the S3 console.

    voila, you should be able to navigate to s3bucket.aws.com/WebGLgame/index.html and play your game using the compressed files.
     
    Sharlei and theANMATOR2b like this.
  14. nbalexis1

    nbalexis1

    Joined:
    Jul 21, 2011
    Posts:
    89
    Hi! is it able to do such things with WebGL in Unity5.3.2?
    We tried:
    1. Build WebGL project from Unity
    2. Remove gz from the end of each filename in /Release/ folder
    3. Remove gz from the end of each url in index.html
    4. Remove .htaccess file
    5. Upload the entire folder to S3, make public.
    6. Modify the content encoding files (appname.js,mem,data) which is originally jsgz, memjz, datajz to application/x-gzip.

    But we have a "SyntaxError: illegal character" error.

    We need help, thanks!
     
  15. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello nbalexis1.

    Did you try all those steps separately or in combination?
    5.3.x builds should normally work without any modifications (you might need to remove the .htaccess on some hostings though). It might however not work properly after some modifications to the server configuration have been made. Could you undo all the server configuration changes, upload the original build to the server and provide the link? (here or privately)
     
  16. nbalexis1

    nbalexis1

    Joined:
    Jul 21, 2011
    Posts:
    89

    We finally make it work!

    It turns out that we are confusing about Content-Type and Content-Encoding.
     
  17. nbalexis1

    nbalexis1

    Joined:
    Jul 21, 2011
    Posts:
    89
    Hi! We make it work though I have not yet check without modifications. Thank you all the same. We just set Content-Type to octet-stream/javascript and set Content-Encoding to Gzip
     
  18. JayaramanC

    JayaramanC

    Joined:
    Nov 7, 2014
    Posts:
    1
    Hello nbalexis1,

    I have tried Content-Type --> "octet-stream/javascript" & Content-Encoding --> "gzip"
    Made the entire folder public.
    Still doesnt work.

    I use Unity 5.3.x to create the WebGL build
    Can you share the full setup details of WebGL on Amazon S3...
     
  19. Ben-Sampson

    Ben-Sampson

    Joined:
    Nov 5, 2014
    Posts:
    10
    CheeseGames.net is a free hosting site for WebGL Unity games.

    Give it a try.
     
  20. JanusAnderson

    JanusAnderson

    Joined:
    Apr 30, 2013
    Posts:
    27
    Just FYI, I followed nbalexis's instructions successfully using a build from Unity 5.3.4 with no issues.

    1. Build WebGL project from Unity
    2. Remove gz from the end of each filename in /Release/ folder

    3. Remove gz from the end of each url in index.html
    note: I did not have to do this step, my index.html did not specify any 'gz' files.

    4. Remove .htaccess file
    5. Upload the entire folder to S3, make public.

    6. Modify the content encoding files (appname.js,mem,data) which is originally jsgz, memjz, datajz to application/x-gzip.
    (this means add the header 'content-encoding: gzip' to the 3 files up on S3, I did this with the free Cloudberry Explorer application)

    7. everything works just fine! I don't see any more gzip decompression delays when loading the game of of S3.
     
    polytropoi likes this.
  21. wendigo

    wendigo

    Joined:
    Nov 21, 2013
    Posts:
    7
    This not works for me.

    I am getting this message in the browser console:

    Invoking error handler due to
    Uncaught SyntaxError: Invalid or unexpected token


    My files are all Content-Encoding gzip and permissions to everyone.
    index.html
    Release/UnityLoader.js
    Release/WebGL.asm.js
    Release/WebGL.data
    Release/WebGL.js
    Release/WebGL.mem

    Thanks in advance.
     
    Nolex likes this.
  22. Nolex

    Nolex

    Joined:
    Dec 10, 2010
    Posts:
    104
    I have a same problem. Unity 5.4
     
  23. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    55
    Hi I'm trying to host in s3 and I have to make it as a public folder and gzip doesn't work. How to make gzip work in s3 and can I run without making the files public?

    [EDIT : I'm using unity 2018.3]
     
  24. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    It doesn't make sense to not make the Unity-specific S3 files public as the only alternative access method would be via S3 directly. You can still have your S3 bucket's default visibility be private though.

    Regarding gzip compression, assuming by "doesn't work" you mean you're getting the JavaScript message about it not being decompressed automatically by the browser, you simply need to apply the Content-Encoding header with the value 'gzip'. You can do this directly via the AWS management console or an S3 browser like CloudBerry. Only apply this metadata to the unityweb files.

    My project is hosted via S3, the only thing that's somewhat difficult to get working regarding storing Unity WebGL builds is streaming instantiation which is a 2019.1 preview feature.

    Edit: Added important note I previously left out, sorry!
     
    Last edited: Feb 5, 2019
    Umresh likes this.
  25. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    55
    Added Content-Encoding(Metadata) to 'gzip' directly via the AWS management console to folder in bucket and make public. When opening the index.html it says cannot reach the page.
     
  26. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Ah yes it's 'Metadata' when done through the management console, that's correct. If you're getting an error saying it cannot find the page that's a bit odd. Are you able to share the URL to the index page? If not that's fine, but am simply trying to diagnose the issue.

    My own application is behind a secure API so unfortunately I can't use it as an example directly, but just to rule out any misconceptions I can run you through an example.

    If your S3 bucket name is my-bucket and you've uploaded the index.html and the corresponding Build folder from the WebGL output directly to the root of your bucket, it should be accessible (regardless of AWS region) from

    http://my-bucket.s3.amazonaws.com/index.html

    Keep in mind S3 isn't really intended as a web server so it won't automatically add the 'index.html' on the end for you - this would be something the Cloudfront service handles though. You should at least be seeing something - if you're getting a 403 just trying to open the page, you should verify all the files are definitely given public ACLs (just read, not write). I can't really suggest anything more than that as it doesn't sound like a Unity WebGL related issue at the moment.
     
  27. Will_Croxford

    Will_Croxford

    Joined:
    Mar 7, 2018
    Posts:
    5
    Hi, I got first part of my game hosted now on AWS, but it is not reading the JSON file in the Streaming Assets folder. This JSON file is read properly with same build on local host my computer. Game is at: https://s3.eu-west-2.amazonaws.com/hellsbellsthegame/index.html (can't go very far in it as I have general issue with it being too big; need to bundle assets next). This is in S3 bucket, which I understand means a static website so only client-side Javascript can run, does this affect Streaming Assets folder?

    In the Access Control List tab for the bucket, for the Group "Everyone" have Read bucket permissions showing as "Yes" and the other permissions as "-". In the Permissions tab for this JSON file in particular, for Everyone group have Read object as "Yes" and other permissions as "-". No actual ACL scripts written (tried this at first, thought I had copied standard public one but clearly still blocked access, so gave up on that one).

    JSON file itself can be viewed at (spoiler alert): https://s3.eu-west-2.amazonaws.com/hellsbellsthegame/StreamingAssets/DungeonQuestions.json and as I said, this JSON file does load when same build run on local host.

    In case relevant: I didn't do anything with .htaccess file (mentioned above don't really know what this is), and just built the WebGL where you get 4 .unityweb, 1 JSON and 1 Javascript file in the Build folder, in Unity Build Settings configured: gzip compression, 256MB build, Full stack trace, Linker Target: Web Assembly, Name Files As Hashes yes, Data caching yes, Debug symbols yes.

    I'm very new to AWS and still my first game in Unity though it dragged on for ages with WebGL deployment problems, thanks any tips!
     
  28. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Will_Croxford likes this.
  29. Will_Croxford

    Will_Croxford

    Joined:
    Mar 7, 2018
    Posts:
    5
    Yes thanks so much triple J @JJJohan exactly that, I just changed file name from .json to .JSON and it works. As URLs themselves are not case-sensitive I would have taken ages to work that out, of course loading the file name and assigning URL are two different things entirely
     
  30. TheRoccoB

    TheRoccoB

    Joined:
    Jun 29, 2017
    Posts:
    53
    AWS can be a little painful.

    Personally I would recommend Firebase hosting or Github pages. Firebase is really just a helpful wrapper around google cloud, and they have great hosting tutorials on line. It's got a generous free plan.

    However if you want to do AWS, I wrote some articles! These could be a little out of date, but hopefully still relevant
    https://hackernoon.com/how-i-built-and-deployed-a-webgl-game-to-a-new-website-in-35m-15b2e8339c31
    https://hackernoon.com/secure-flappy-bird-https-just-got-insanely-easy-on-aws-6fe1d41ed12f

    If you want to do github pages, check out this video I made
    Github also has a mechanism for connecting a domain to your pages.

    FYI I run the Unity WebGL site SIMMER.io with Firebase hosting FYI, after giving up on AWS because of its difficulty of use.

    Finally, to improve the look of your hosted, game, consider using https://assetstore.unity.com/packages/tools/gui/responsive-webgl-template-117308

    Hope this helps!
     
    ARTfunny and Will_Croxford like this.
  31. ARTfunny

    ARTfunny

    Joined:
    Mar 15, 2019
    Posts:
    3
    SIMMER.io is the way to go, I recently signed up and it is a piece of cake to use thank god !
    I have been struggling with this issue and gave up on getting my game onto my site until I found Simmer.io
    It is straight forward, easy to use I cant recommend it enough.
    Create your WEB GL build
    Drag it into the simmer uploader
    Add some titles & tags
    Then copy the link into your HTML plugin (I use wix)
    it just works, there are free and paid subscriptions to chose from.
    I have no connection to simmer other than being a happy customer
    Thanks Rocco, Good Job!
    https://simmer.io/
     
unityunity