Deploy your app on AWS EC2 with NGINX and SSL

Hi,

Recently AWS is charging for static IP address unless used via EC2 instance, so you can't deploy via ELB (if you are poor that is).

Do the usual stuff, spin up an EC2 instance (allow http and https) with ubuntu as OS and copy your source files. Install the dependencies and lets say your app runs on port <PORT>

Now the proxy part

  1. Install NGINX

     sudo apt install nginx
    
  2. Edit the nginx config

     sudo nano /etc/nginx/sites-available/default
    
     server_name yourdomain.in www.yourdomain.in;
    
         location / {
             proxy_pass http://localhost:<PORT>; 
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
             proxy_set_header Host $host;
             proxy_cache_bypass $http_upgrade;
         }
    
  3. Before restarting NGINX, add the A record with the IP address of the EC2 instance to your custom domain. After that

     sudo service nginx restart
    
  4. Now you can access you app from http://yourdomain.in

  5. Now we go on to add the SSL

  6. Install Certbot

     sudo apt-get update
     sudo apt-get install python3-certbot-nginx
    
  7. Use Certbot CLI and you get some questions, I'm sure you will be able to figure it out

      sudo certbot --nginx -d yourdomain.in -d www.yourdomain.in
    

Now you can access it via https://yourdomain.in

That's it folks.

0
Subscribe to my newsletter

Read articles from Krishna Chaitanya Terala directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krishna Chaitanya Terala
Krishna Chaitanya Terala