Search code examples
nginxember.jsamazon-s3redisember-cli

Ember Cli Deploy via Lighting Strategy


We have deployed our Ember App using Lightning Deploy Strategy which involves:

  • EC2 instance
  • Nginx (HTTP Server)
  • Redis, configured on same instance (to serve index.html)
  • compiled js and assets from AWS S3

When, upon hitting the instance, the index.html gets served from Redis, and subsequently on clicking any route in the App, the App routes get served.

But, when we manually enter any correct route in URL for the Ember App, Nginx throws an error saying route not found. Anything wrong that we are doing here?


Solution

  • When a subrequest, say, mydomain.com/login is hit with the url or the page is refreshed, the browser sends a requests to nginx and nginx won't be able to find the login page anywhere and will return a 404 error. This is because nginx won't be able to pass the subroutes to index.html page which in turn can serve the subroutes. To solve this the following location block is used in nginx.

      # This block handles the subrequest. If any subroutes are requested than this rewrite the url to root and tries to render the subroute page by passing the subroute to index file (which is served by the redis).
      location ~* / {
      rewrite ^ / last;
      }
    

    Here we are saying to nginx, for any subrequests, rewrite the url to root (/) location (root location serves the index page from redis) and find the requested page. The last option tries to find the particular page by revisiting all the blocks defined in nginx as a result of which it is able to go to root location. A detailed explanation and full nginx config can be found here.