aws beanstalk nodejs redirect http to https

  1. Create a file named force-https.config in the top-level .ebextensions directory of your Node.js application.

  2. Inside force-https.config, add the following configuration to redirect all HTTP requests to HTTPS:

files:
  /etc/httpd/conf.d/force-https.conf:
    mode: "000644"
    owner: root
    group: root
    content: |
      <VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{HTTP:X-Forwarded-Proto} !https
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
      </VirtualHost>
  1. Deploy your application to AWS Elastic Beanstalk to apply the configuration changes.

  2. After deployment, all incoming HTTP requests will be automatically redirected to HTTPS.