Welcome to a hassle-free journey of deploying your Nodejs app on AWS EC2 with SSL configuration! In this quick guide, we’ll walk you through the straightforward steps to effortlessly host your application while ensuring a secure connection. Say goodbye to deployment complexities and hello to a smooth, secure, and swift hosting experience. Let’s dive in and have your node app up and running in just a matter of minutes!
Step 1: Create AWS EC2 Server and Connect with VS Code using SSH
=> Connect to your EC2 instance from Visual Studio Code using SSH.
=> Ensure that all required ports are open in the AWS security group.
Step 2: Set Up Node.js App Directory
=> Use VS Code to clone your repository into the `/home/ubuntu/` directory.
Step 3: Install Node.js and npm
=> Run this command in Terminal
sudo apt update
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install 16.15.0
nvm use 16.15.0
sudo apt install npm
sudo npm install -g pm2
Step 4: Install and Configure Apache
sudo apt install apache2
sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests
Step 5: Create a Reverse Proxy Configuration
=> Create a Virtual Host File
sudo nano /etc/apache2/sites-available/reverse-proxy.conf
=> Replace “your-domain-or-ip-address” with your domain or IP.
<VirtualHost *:80>
ServerName your-domain-or-ip-address
ErrorLog ${APACHE_LOG_DIR}/react-app-error.log
CustomLog ${APACHE_LOG_DIR}/react-app-access.log combined
ProxyPass / http://localhost:6222/
ProxyPassReverse / http://localhost:6222/
</VirtualHost>
=> Press CTRL + X, enter Y and press Enter 2 times.
Step 6: Enable Reverse Proxy Configuration
sudo a2ensite reverse-proxy
sudo systemctl restart apache2
Step 7: Configure SSL Certificate
sudo apt install python3-certbot-apache
sudo a2enmod ssl
sudo systemctl restart apache2
sudo certbot renew --dry-run
sudo certbot --apache
sudo certbot renew --dry-run --standalone
Step 8: Configure SSL with Domain
=> Edit the SSL Virtual Host Configuration.
sudo nano /etc/apache2/sites-available/your-domain.conf
=> Replace “your-domain.com” with your domain.
<VirtualHost *:443>
ServerName your-domain.com
# SSL configurations
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/your-domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/your-domain.com/chain.pem
</VirtualHost>
=> Press CTRL + X, enter Y and press Enter 2 times.
Step 9: Restart Apache And configure MariaDB
sudo systemctl restart apache2
sudo apt-get install mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql -u root -p // after this command press Enter
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
Step 10: Run Node.js App
=> Move to your Node.js application folder and run the following command
pm2 start app.js
Thank you for taking the time to read my article on Medium. I hope you found it informative and helpful. If you have any questions or feedback, feel free to reach out. Happy coding!