I have a React app with Django for the backend and mysql database. I want to host this website on ec2. I have also purchased a domain. currently, I am running the React server and Django server on the ec2 instance and I am able to access this website using the elastic IP address assigned to the instance, something like public-address:3000.
I want to be able to link the domain with the ec2 instance. I have configured my domain to be linked to my instance using DNS, but the problem is the react server is running on the local host of the ec2 instance, and when I access the domain, I can't view the website.
Can someone help me out with this
You are having the app running on port 3000 which is why it is accessible to you when using the EIP:3000. The same will work for domain too but you have to mention the port like http://<domain-name>:3000
. While you can change the app configuration to run on port 80, it is recommended to have some "middle-man" to do that job for you. You can use an NGINX reverse proxy on the same instance to listen on port 80 and then forward that to port 3000 towards your app.
If security is your priority (and it should be), it is recommended to expose the app via an Application Load Balancer or via CloudFront (if your clients are global). In both these options, you can get free certificate for your domain from AWS using ACM (Certificate Manager).
For ALB, use the link to set this up. Steps in short are as below: