-1

I have created an AWS EC2 instance with Node and Mongodb installed in it. This is backend code. Also I have frontend react code which is deployed in cloudways, so to connect this with the backend code, I have given the ipaddress of ec2 instance in the frontend (React).But when I try to connect these both(Eg. Login page(Frontend react code) - when i submit the login details it has to hit backend (mongodb)). It does not the even hit backend url rather throws this error in browser console.

The error is:

Mixed Content: The page at 'https://www.mywebsite.com/signup/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://(ec2-ip-address)/api/apiname'. This request has been blocked; the content must be served over HTTPS.

But When I tried to hit the backend(EC2 IpAddress) in postman app. I can able to save or retrieve data from mongodb which is installed in Ec2 Instance.

  • 1
    The error message very clearly states what the problem is. The web browser is refusing to let you mix secure and non-secure servers. You can hit the non-secure servers directly with tools like postman all you want, but the web browser isn't going to let you hit that non-secure server from your secure website. – Mark B Jan 28 '22 at 19:54
  • @MarkB Yeah I understood the error. But I am not sure how to make it secure with AWS Ec2 instance, Since the website is not hosted in aws, but only the node application(To connect with mongodb). – Gayathri Jan 28 '22 at 20:05
  • The node application is another web server. You will need to add a domain name to that service, and an SSL certificate. Just like you would to any other web server. – Mark B Jan 28 '22 at 20:08
  • @MarkB Thank you for your quick response. Can you please share me some reference links on how to add domain name to that aws ec2 instance and make it secure. FYI, my aws instance has only node and mongodb installed. – Gayathri Jan 28 '22 at 20:10

1 Answers1

0

you need to allow Insecure Content in your browser, to make it work you need to change setting in your browser. refer below link for "Google Chrome"

link

MrOverflow
  • 407
  • 3
  • 8