aham
aham

Reputation: 137

Deploying Ember JS application in EC2

I would like to deploy ember app in an EC2 ubuntu instance.

I dont know how to make the tomcat run the dist files that is generated during the build. Can someone explain it in a step by step so that I can understand clearly?

Upvotes: 0

Views: 260

Answers (1)

mistahenry
mistahenry

Reputation: 8724

I don't think you should be serving the Ember app from Tomcat. At least in the past when I evaluated, Tomcat is much slower at SSL than Apache/Nginx, isn't as fast with static content, requires redeploys of the WAR file if you change static content, and lacks the configuration options of the more commonly used HTTP servers. Better approach, reverse proxy to your app server (I assume you are running a java app since you are using Tomcat). Serve the Ember app from the reverse proxy. If you are running SSL, you would handle it all from the reverse proxy and not tomcat. This is how I serve my Ember app and my Spring Boot app (the api powering my ember app) from the same EC2 instance.

I'll show you how I do it on redhat but you'll have to translate for ubuntu (as in you have apt-get where i use yum, etc).

  1. Install apache on your VM yum install httpd -y

  2. Configure apache as a reverse proxy in /etc/httpd/conf/httpd.conf

<VirtualHost *:80> ProxyRequests Off ProxyPass /api http://localhost:8080/api ProxyPassReverse /api http://localhost:8080/api </VirtualHost> FallbackResource /index.html

This has two very important parts. First, you run your tomcat serve on http://localhost:8080/ (not on 80!) and have a servlet underneath api or something other subpath. You need this sort of distinction so that your ember urls do not conflict with your api urls. As in, if you are wanting your Ember app to run under / and you have an api endpoint under /users and an Ember route /users, how can you distinguish which should be served? I argue that your api should run under /api/users to avoid collisions.

Second, the FallbackResource /index.html allows unmatched directories to return your index.html file. See, when your browser makes the request: yourapp.com/someRoute to your server, you need your http server to simply return the index.html file. Ember will then take care of the routing on the client side. This means, regardless of what route you are on in Ember, when the browser asks for that url, you should always return index.html. I don't even know how you would configure a rule like this in tomcat (you'll have to research rewrite rules/directives if you don't want to use a reverse proxy).

  1. Lastly, within http.conf find the document root: eg. DocumentRoot "/var/www/html". This is the path on your EC2 server where your static files are served from. This is where the contents of your dist folder belong. For me, a typical deployment means ember build, scp to the server, sudo rm -rf /var/www/html/ and sudo cp -r dist/. /var/www/html to replace the old ember app with the new. This works for me because the contents of my ember app are the only static files that I need to serve. If you have other needs, you can't just delete and replace the old document root like I do.

Make sure httpd/apache is running! service httpd start on redhat. You don't have to restart the server when changing out files.

Upvotes: 1

Related Questions