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
Install NGINX
sudo apt install nginx
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; }
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
Now you can access you app from http://yourdomain.in
Now we go on to add the SSL
Install Certbot
sudo apt-get update sudo apt-get install python3-certbot-nginx
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.
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