how to rewrite my application url to my domain in AWS - .htaccess

I have EC2 instance created in AWS the ip is for example 54.26.12.***
I have my domain (mydomain.com) registered with S3bucket for this EC2 instance, Now this domain shows the index page provided by AWS.
Now 54.26.12.*** is available while hitting mydomain.com in browser.
In this instance, I deployed a war file to tomcat server and I am able to run this as mydomain.com:8080/myAppUrl.
I am looking for show this application url while hitting mydomain.com in browser.
I can put .htaccess file to rewrite urls. But in AWS I cant do that as it is not supported.
How do I rewrite in AWS to my app for my domain.
Update
domain screen now

you could add a A record on your provider (route53, GoDadddy, NameCheap ...) to point myapp.mydomain.com on your ec2 instance.
On the ec2 instance you would need to run apache to listen on port 80 and forward to your app server the requests.
Otherwise you need to change your current A record on domain.com to point to your ec2 IP address and not the S3 bucket

Related

How to point AWS EC2 Server to my Godaddy domain

I have MERN stack app and both Reactjs and Nodejs are running on Same host/IP of EC2 . I have bought a domain from Godaddy so how can i point it to my domain . Am getting this error on Godaddy
Also how can i add SSL certificate for both (Frontend and NodejsServer / both running on same instance with different ports e.g 3002:react , 4000:nodejs)
It can be achieved using Route53, providing high level overview here and pointing to the AWS Documentation
Set static IP of your EC2 instance (Elastic IP)
Configure hosted zones in Route53
Create records in Godaddy
Full documentation here https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-ec2-instance.html
It depend how you want to setup SSL for FrontEnd and Backend
Ideally for FrontEnd you point your domain to the right port of FE 3002 so that when you open your site www.mysite.com then it opens your FE
For BE, you can use your static IP or the AWS provided host name and to setup SSL follow this SO post
Frontend (domain.com and www.domain.com)
Use AWS apmilify to host your static files, it will give you dns record that you can add on godaddy.
Backend (server.domain.com)
Put a loadbalancer Infront of your ec2 instance that will handle ssl and it will give you a dns record that you can add on godaddy. Loadbalancer should listen on 80 and 443 ports and can forward to 4000 on ec2 instance.
please note this is just a quick recommendation just for your use case, there are many better ways to deploy MERN apps.

How do I enable SSL for a subdomain that points to an Amazon EC2 instance (Elastic IP)?

I'm trying to enable SSL on a subdomain from a domain I purchased from Google Domains (Managed with Netlify DNS). The domain is currently pointing to a static react app hosted by Netlify (it has SSL).
The subdomain (api.example.com) pointing to an elastic IP associated with an EC2 instance doesn't seem to be working when I try to access it with HTTPS (api.example.com’s server IP address could not be found.) but works with HTTP.
Does anyone know of a way I could use that SSL certificate I got from Netlify on the subdomain pointing to my aws instance?
I'm using only an A record for the subdomain -> elastic ip. For the purpose of getting everything to work, I've enabled all inbound/outbound ports for all traffic types on my instance security group.

Configure subdomain in express-subdomain?

I am trying to use the directions given in
https://www.npmjs.com/package/express-subdomain
to set up subdomain.
I a hosting my server in amazon EC2 and the DNS provider is google-DNS.
but I am getting error while accessing the page.
404. That’s an error.
The requested URL / was not found on this server. That’s all we know.
So I need to do any configuration in EC2 or in my DNS?

How to configure Nodejs that is in AWS EC2 Instance to accept HTTPS request from client side

I would like to ask about how to configure Nodejs (backend/server) to accept HTTPS request from client side (Front end).
What we did.
Registered domain name in AWS.
List item
Requested SSL in ACM.
Create bucket in S3, and store our front-end code (angular 5) inside of it.
Created distribution in cloud front and put our custom ssl there and connect to bucket in S3.
We set up also ec2 instance and store our back-end code (node js) there.
In our front end code we connect to the ip of our ec2 instances so that we can connect to backend.
The problem:
The front-end can't access the backend in ec2 instances because the front end is https and the backend is http (we don't know how to configure it from http to https in AWS EC2 Instance).
Do you know how to setup web app in aws which front end and backend code is separated?
What did we missed?
What did we missed?
If I understand you correctly, you have a Cloudfront distribution serving angular which is then attempting to connect to an EC2 instance - I presume the IP address or public DNS entry for the EC2 is hard-coded into the angular code.
This is not a good arrangement - if your EC2 goes down or the IP address changes you will need to push a new site to S3 - and then this change will take time to propagate through Cloudfront.
What you should rather be doing is this.
create an application load balancer
create a target group and add your EC2 to that target group.
add a listener on the ALB, listening on the port your web app connects on, with a rule that forwards to the HTTP port of the back-end EC2.
Add a route 53 DNS Alias record for the ALB (because ALBs do sometimes go away or change their IP address)
Change your front-end code to point at the Route 53 Alias record.
(This is an incredibly simplistic way of doing things that leaves your EC2 open to the internet etc etc).
You should also give serious thought to putting your EC2 into an autoscaling group that spans at least two availability zones, and to setting its minimum size to ensure at least servers are running at any one time.
AWS EC2 instances can go away at any time, and when they do your app goes down with them.

Register GoDaddy Domain with AWS ec2 instance

My Problem is as below.
I have a domain registered with GoDaddy [ assume : mytest.com ]
I have a EC2 ALM instance at AWS
I have elastic IP associated with my Instance [ assume : 111.222.333.444]
I have developed a nodejs application and deployed in instance
That node application is running at port 8181
Application is accesable using http://111.222.333.444:8181/
I want to configure my domain so that http://mytest.com will point to http://111.222.333.444:8181/
I have few knowledge to configure using Route53 also but not able to solve the mapping with port 8181.
Need kind help to resolve this issue
Thanks in advance
Note : For time being i am not looking for AWS PaaS Elastic Beanstalk for node js deployment
Ajoy
You actually have to do several things to make your thing work.
1. Change DNS nameservers to point to your Route53 Hosted Zone
Since you registered your hostname with GoDaddy, and you want to use Route53 as your DNS, you have to do several things.
First, go to Route53 and create a hosted zone for your domain. For demonstrative purposes, I will be using stackoverflowexample.com as my domain.
After you've created your hosted zone, click into it and you should be presented with the NS and SOA records. The NS record lists 4 unique nameservers that you will need to configure with GoDaddy.
The image below is an example of the NS record set (AWS Route53 calls it the delegation set).
Then you will have to go to your registrar and follow their directions to change nameservers for your domain, using the 4 nameservers Route 53 assigned you as your custom nameserver.
Then create a new A record in route 53 pointing at your elastic IP address. In the end your Route 53 zone will look something like this, with an A record mapping your domain to your elastic IP address.
2. Hosting/proxying your application on default HTTP port
After you have set up the DNS records (and waited a while for DNS to propagate), then you should be able to hit your server on port 8181.
But you want to hit it without a port number, so how do you do that?
DNS itself doesn't care about ports, it really just provides information about IP addresses and domain names. What you need now is to set up a proxy or other mechanism to direct traffic on your server. I will provide a few solutions.
Use nginx to reverse proxy
Since you control your own instance, you could install nginx (a web/proxy server) on the instance and configure it so that when it gets requests, it knows how to direct the traffic.
Here are generic instructions for configuring nginx for reverse proxy operation.
nginx example for Debian/Ubuntu
If you are using Debian or Ubuntu, a simple set up is as follows:
# Install nginx
sudo apt-get update && sudo apt-get install nginx
# By default, nginx runs a default site on port 80 you don't care about
# This removes the symlink for the default nginx site
sudo rm /etc/nginx/sites-enabled/default
Then you will want to create your own configuration in sites-available.
sudo vim /etc/nginx/sites-available/mainsite
The contents of your file will look probably like this:
server {
listen 80;
server_name stackoverflowexample.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
# Proxy all requests to the NodeJS app on port 8181
proxy_pass http://localhost:8181;
}
}
After you're done, execute the next two steps
# symlink your new nginx config to sites-enabled, which nginx
# automatically discovers and loads.
sudo ln -s /etc/nginx/sites-available/mainsite /etc/nginx/sites-enabled/mainsite
# Reload nginx configuration
sudo service nginx reload
Now try hitting your site without the port - you should reach your application.
Use Elastic Load Balancer
AWS offers a load balancer service (at an additional cost of ~$20 USD per load balancer per month) which lets you configure an HTTP and/or HTTPS load balancer for your application, allowing you to map incoming request ports to ports on your instance.
It's also automatically provided to you if you use Elastic Beanstalk.
They have their own tutorial which should help.
Configure your application to run on port 80
I do not do this myself and this is only useful if your instance will only ever host one app that controls all its own routing.
You could run your Node app directly on port 80 without needing a reverse proxy in front. If you go down this route, I'd recommend not allowing the service to run as root and instead configuring something like authbind to allow non-privileged access to port 80.
I will defer to other answers like this SuperUser one if you want to bind your service to port 80.
Additional Notes
You'll note that I excluded configuring HTTPS. That requires more steps like provisioning an SSL cert, though AWS or LetsEncrypt provide them for free now. Configuration also differs if you're using an Elastic Loadbalancer or a server on your instance, or if you're exposing your app directly.
I suggested nginx, and I would still recommend it in almost all general cases, but there are multiple different servers you could use to act as a reverse proxy. Other popular ones are haproxy or apache httpd with mod_proxy.
You can use any AWS public gateway provider such as EC2, ELB, S3 to serve your website or server to the public domain you have on GoDaddy. The AWS usually charges about .51 USD per month to maintain this zone entry as well.
the following steps set up your domain.
Obtain the Elastic IP or EC2 IP for the website or service.
Create a Hosted Zone on Route53.
Update the domain name records on Hosted Zone.
Update name servers on GoDaddy for discovery.
Check this tutorial
For those who are only looking to route their domain to ec2 instance (have already running ec2 instance and having domain name).
1.) Go to: https://dcc.godaddy.com/domains and select your domain.
2.) Click on Manage DNS and edit Record Type A.
3.) Enter your ec2 instance public ip in Points to textbox. Save. Done.

Resources