DEV Community

How To Deploy Your Node.js App On AWS With NGINX And SSL

Shadid Haque on March 29, 2021

Photo by Bill Jelen on Unsplash Originally published in my blog In this tutorial, we will briefly go over the process of deploying a Node.js/...
Collapse
 
salis010 profile image
Stephen Saliba

I tried many similar articles, but many failed, yours is the best I found. Thank you a lot.

May I just point out to a tiny typo: in the nginx installation command, 'Nginx' should be in lower case, the below does not work:

sudo apt install Nginx
Enter fullscreen mode Exit fullscreen mode

Anyway, you earned a follower.

Collapse
 
shadid12 profile image
Shadid Haque

Thank you Stephen. I totally missed that one. Glad that I could help 😀

Collapse
 
adrienfloor profile image
Floor

Thank you for the great article ! Could you explain how to setup env variables on the created instance ? I couldn't find a clear answer ... Thank you !!

Collapse
 
abdurrkhalid333 profile image
Abdur Rehman Khalid

What an awesome article this is. It has Helped me a lot and I am bookmarking this article so that I can come here again and again. Thank you and I will also be implementing the same technique with deployment of the Angular Application as well.

Collapse
 
shadid12 profile image
Shadid Haque

Thank you, means a lot. Feel free to reach out on twitter.com/haqueshadid

Collapse
 
ithinkobjects profile image
Marlon • Edited

This is really cool! Thanks for sharing the insight. I look forward to coming back to this every now and then!

Collapse
 
bonaparteit profile image
BonaparteIT

After command:

sudo add-apt-repository ppa:certbot/certbot

The PPA has been DEPRECATED.

To get up to date instructions on how to get certbot for your systems, please see certbot.eff.org/docs/install.html.
More info: launchpad.net/~certbot/+archive/ub...

Collapse
 
ashadnasim52 profile image
ashad nasim

Awesome Article, but for Nginx part, your article is not correct. The correct way is

  1. Install NGINX and configure sudo apt install nginx

sudo nano /etc/nginx/sites-available/default
Add the following to the location part of the server block

server_name yourdomain.com yourdomain.com;

location / {
proxy_pass localhost:5000; #whatever port your app runs on
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;
}

Enter fullscreen mode Exit fullscreen mode




Check NGINX config

sudo nginx -t

Restart NGINX

sudo service nginx restart

Taken from gist.github.com/bradtraversy/cd90d...

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

Thank you and God bless you.... I am really happy for this.

It worked like charm

Collapse
 
akdenied profile image
akdenied • Edited

nginx -t fails
I think because

server {
    server_name yourdomain.com www.yourdomain.com;
    location / {
        proxy_pass http://localhost:8000; # your app's 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;
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mdmohsinghazi1 profile image
MD Mohsin Ghazi

Getting this after configuring all configuration on EC2-instance
"ErrorResponse is not defined"