• Home
  • Posts
    • All Posts
    • All Tags
  • Projects
  • About
    • just4fun photo

      just4fun

      Zoro's personal blog.

    • Learn More
    • Email
    • Facebook
    • Instagram
    • Github
    • Weibo

Deploy meaning on Amazon EC2

04 Jan 2015

Reading time ~2 minutes

meaning is a mini blogging platform inspired by MEAN.JS(MongoDB, Express, AngularJS, and Node.js), and I will take notes here about how I deploy it on Amazon EC2.

Amazon EC2

First of all, you should pay for an Amazon Machine Image to launch an instance. I choose Ubuntu and what is more, I buy an extra Reserved Instance to receive a discount on my instance usage compared to running On-Demand instances. You can know more about Reserved Instance here.

Release

Now, we should release project to get the released code which will be deployed to production.

$ grunt build -release

And the dist folder contains all the released files.

FTP

For Windows, FileZilla is a nice choice for FTP solution. And for Mac, I like Transmit.

First, copy your Amazon EC2 .pem file to your local ssh directory ~/.ssh. Next, open ~/.ssh/config and add extra line to let your app know the PEM, for example:

IdentityFile "~/.ssh/just4fun.pem"

At last, save the config changes and alter the permissions of the PEM file to 700:

$ chmod 700 ~/.ssh/just4fun.pem

Try command below to test whether the PEM file works:

$ ssh -i ~/.ssh/just4fun.pem root@your_amazon_server

When we connect our server successfully, we should create a virtual host which will contains the released files:

$ mkdir /var/www/just4fun

Then copy directories and files to the virtual host which we created just now:

/dist/client
/dist/server
/package.json

Tap commnd below to install the node dependencies:

npm install -production

At last we get directory structure like below:

/var/www/just4fun
  --client
  --server
  --package.json
  --node_modules

DB

We use MongoDB in meaning and there is a post about how to install MongoDB on Ubuntu(14.04) for reference. Or you can visit official site to find the installation.

Web Server

I previously use Apache, and I changed it to nginx now. In order to install Nginx we execute:

$ apt-get install nginx

Then create a virtual host configuration file in /etc/nginx/sites-available, such as /etc/nginx/sites-available/just4fun.

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  root /var/www/just4fun/client;
  index index.html index.htm;

  # Make site accessible from http://localhost/
  server_name talent-is.me;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    rewrite ^/admin/?$ /admin/admin-index.html break;
    rewrite ^/login/?$ /admin/admin-login.html break;
    try_files $uri $uri/ =404;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
  }
}

Next, we should disable the default vhost:

rm /etc/nginx/sites-enabled/default

And enable our virtual host:

ln -s /etc/nginx/sites-available/just4fun /etc/nginx/sites-enabled/just4fun

At last, restart nginx with new configuration:

service nginx restart

That’s all. :)



ec2transmitnginxmongodb Share Tweet +1