I have builded an EC2 that have frontend with VueJs and backend with NodeJs (backend and frontend in one instance)
I have set the inbound security group to accept traffic from 127.0.0.1, public and private IP of the instance itself.
But the frontend site always can not call API to the backend. I have change the backend IP to call from frontend with:
but still didn't work.
I have re-set the inbound security group to 0.0.0.0/0 then it works.
From the backend, I print out the request IP and it returned an IP that totally not related to any IP of the instance.
I re-set the inbound security group to that strange IP and it still work.
But when the instance turn off and on again, that strange IP has been changed althought I set Elastic IP for my instance.
How can I call API from my frontend to backend with localhost or it own public or private IP?
Thanks for reading!
Thanks for your answer. But that IP changed everytime I stop and start the instance again. If that is my PC public IP, I think it was stable.
Is it possible that the IP address of your ISP has changed?
If you configure the web server to use a proxy when accessing the API endpoint, the backend access will be localhost. For example, when I had an API like "/api/test", I think that if I set a proxy when accessing this URL, it would be accessed using localhost or a private IP of EC2.