Monday, March 5, 2018

routing - EC2 with elastic IP & Route53 DNS - Domain is resolving to incorrect public DNS



Newbie here, please let me know if I can add any more details or if I'm missing something entirely obvious.



I got my site up and running on an EC2 and I was able to view it with the public DNS.




I pointed my domain to the instance using this guide. I created an elastic IP for the instance, I created four NS records and two A-name record (www, non-www) using route53. I passed these NS records to my domain provider.



The domain appears to have propagated - when I go to the URL, I get redirected to a very old (two restarts ago) public instance DNS address instead of the new one with the elastic IP. I CAN SSH in to the instance using the new domain name but I can't access it from the browser. I checked my security groups, and HTTP/80 is set to allow all traffic.



I tried accessing the EIP directly (redirect), pinging the EIP (time out), accessing the Public DNS directly, pinging the Public DNS, I tried stopping and starting the instance and repeating all previous steps, and I checked that port 80 is open in the security group, but the domain still redirects me to an old public DNS.



Chrome gives me the error ERR_CONNECTION_TIMED_OUT in the browser after I (301) redirected to the old URL.



Not sure where to go from here.


Answer




Looking into the issue, doing a nslookup on the domain gives me:



Name:   www.racheldoesfestivals.com  
Address: 34.197.64.48


This is an IP belonging to AWS, so I'm assuming this is going to the right place. I would check to see if that matches the EIP, but based on what I'm seeing below, I'm going to assume this is correct.



Using curl against that IP, I get:




[root@server nginx]# curl -v 34.197.64.48
* Connected to 34.197.64.48 (34.197.64.48) port 80 (#0)
> GET / HTTP/1.1
> Host: 34.197.64.48
> User-Agent: curl/7.47.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 31 Mar 2017 14:04:00 GMT
< Server: Apache/2.4.25 (Amazon) PHP/5.6.30

< X-Powered-By: PHP/5.6.30
< X-Pingback: http://ec2-54-211-187-124.compute-1.amazonaws.com/xmlrpc.php
< Location: http://ec2-54-211-187-124.compute-1.amazonaws.com/
< Content-Length: 1
< Content-Type: text/html; charset=UTF-8


This shows to me that I'm indeed hitting a webserver running on 34.197.64.48, but the webserver I'm reaching thinks I should be somewhere else, and is forwarding me to http://ec2-54-211-187-124.compute-1.amazonaws.com/ (This is not Route53 related).



This means that somewhere on the webserver located on 34.197.64.48 there is some code that is triggering a redirect. This could be in your webserver (apache) config file, it could be a .htaccess file, or could be in the application itself.




A lot of websites during the setup phase, make you input a 'primary' website address, which you get redirected to if you visit in any other way. In the past trying to solve this with Wordpress (if this was miss-configured on initial setup) you needed to modify a setting in the database before you can visit the website without being redirected.



I can confirm that we are getting to a working webserver and DNS is working, because running the following command:
curl -vH "Host: ec2-54-211-187-124.compute-1.amazonaws.com" 34.197.64.48
Which tricks the webserver into thinking I'm visiting the website returns me html of:
RachelDoesFestivals - Guides, musings, media, and other nonsense from a festival obsessionist



If you are patient, you might be able to get into the website using:
http://www.racheldoesfestivals.com/wp-login.php
Then fixing the site address in settings->general



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...