Configuring the SSL Certificates on your EC2

Configuring SSL Certificates on EC2 with Nginx

Securing your web applications with SSL/TLS certificates is essential for protecting user data and ensuring a safe browsing experience. In this guide, we'll walk through the process of configuring SSL certificates on an EC2 instance hosting both frontend and backend applications using Nginx. We'll also cover how to renew these certificates to ensure ongoing security.

Prerequisites - An EC2 instance with both frontend and backend applications deployed. - Nginx installed on the EC2 instance. - Certbot installed on the EC2 instance for managing SSL certificates.

Step 1: Install Nginx

If you haven't already installed Nginx, use the following commands:

bash sudo apt update 
sudo apt install nginx

Step 2: Obtain SSL Certificates

Use Certbot to obtain SSL certificates for your domains. Replace your-domain.com with your actual domain.

sudo certbot --nginx

Follow the prompts to select the domains you want to secure and complete the setup. Certbot will automatically update your Nginx configuration.

Step 3: Update Nginx Configuration

Verify that your Nginx configuration file includes the SSL certificate paths. Open the Nginx configuration file:

sudo nano /etc/nginx/sites-available/default

Ensure that your server block includes the SSL settings:

server {
    listen 443 ssl;
    server_name your-domain.com www.your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

    # Other SSL configurations...

    location / {
        # Your app settings...
    }
}

Step 4: Restart Nginx

Restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 5: Update React App

Ensure that your React app makes requests using https:// instead of http. Update any hardcoded API or resource URLs in your React app to use the secure protocol.

Step 6: Automate Certificate Renewal

Certbot sets up automatic renewal by default. Verify the renewal setup:

sudo certbot renew --dry-run

This command performs a dry run renewal to check if the renewal process is working.

Conclusion

Congratulations! You have successfully configured SSL certificates on your EC2 instance hosting a frontend and backend using Nginx. Regularly check for certificate renewals to prevent expiration issues and ensure ongoing security.

If you encounter any issues or have questions, feel free to consult the Certbot documentation or the Nginx documentation.

Happy coding and stay secure!