I have a basic Django website hosted on EC2. It is accessabile over the internet when I use the ipaddress. But I want to use my newly purchased domain example.net (purchased from Namecheap). I configured Rout53 for DNS services. When I try to access my website using example.net it doesn’t do anything and gives below error on browser:
"This site can’t be reached example.net refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED"
When I checked the logs on my EC2 server, it does not show any log if I hit example.net on browser but it shows logs when I hit “ip address”.
I performed all below checks and all is working fine as expected:
- DNS Records: Verify DNS records in Route 53. – I checked both A and CNAME record and it is correct
- Security Groups: Confirm security group rules allow HTTP and HTTPS traffic. – Both HTTP and HTTPS inbound rules are open for all.
- Verify ALLOWED_HOSTS in Django – This is how my ALLOWED_HOSTS looks like in my Django settings.py [‘my EC2 elastic ip’, ‘example.net’]
- Firewall Settings: Confirm ufw is inactive or appropriately configured. – I don’t have any firewall configured
- Domain Resolution: Verify using dig or nslookup. – I tried this command on my EC2 instance “dig example.net @” and I get all details as below
; <<>> DiG 9.8.2-0ubuntu5-Ubuntu <<>> example.net @<my Route53 name server1>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34198
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;example.net. IN A
;; ANSWER SECTION:
example.net. 300 IN A <my EC2 elastic ip>
;; AUTHORITY SECTION:
example.net. 172800 IN NS <my Route53 name server1>.
example.net. 172800 IN NS <my Route53 name server2>.
example.net. 172800 IN NS <my Route53 name server3>.
example.net. 172800 IN NS <my Route53 name server4>.
;; Query time: 0 msec
;; SERVER: 2.2.1.2#53(<my Route53 name server1>) (UDP)
;; WHEN: Mon May 27 16:51:50 UTC 2024
;; MSG SIZE rcvd: 191
-
Browser Cache: Clear cache or use incognito mode.
-
Server Reachability: Test local server response using curl. – Curl with my EC2 ip is working fine but curl with my domain name is not working.
-
DNS Propogation: like Whatsmydns.net to see if the DNS records have propagated globally. – This shows green ticks globally.
Please help me or suggest to me what I am doing wrong and where.