0
votes

I want to change from HTTP and use HTTPS for nodejs services using nginx, I have created self-signed certificate

Now, I want to Change From

http://xx.xx.xx.xxx:3000 

To

https://xx.xx.xx.xxx:3000

How to implement this in AWS with EC2 Instance, NGINX or ELB?

1

1 Answers

0
votes
  1. Enable port 443 with the certificate (ACM or LetsEncrypt), along with Port 3000.
  2. Add this below code above the server block in nginx configuration:
 server {
       listen 3000;
       if ( $http_x_forwarded_proto != 'https' ) {
       return 301 https://$host$request_uri;
       }
 }
  1. Restart nginx.
  2. Test

The request will hit the nginx on port 3000 and will redirect it to port 443.

This is untested but works for me on port 80 and 443 combination.