Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Apache redirecting example.com to ec2 public DNS

Setup

Route 53 Domain example.com has A record to id.cloudfront.net and AAAA record to random-id.cloudfront.net.

Cloudfront has origin domain as EC2 public DNS ec.xxxxxx.amazonaws.com and alternate domain as example.com. Also, it has a AWS certificate for SSL/TLS (for now it accepts both HTTP & HTTPS requests)

EC2 is an Ubuntu-20.04 AMI with apache2, php7.4 and phpmyadmin, all installed using apt-get.

Issue is whenever I put in example.com/* the site is automatically redirected to ec.xxxxxx.amazonaws.com/*.

Example:

  • example.com/phpmyadmin gets redirected to ec.xxxxxx.amazonaws.com/phpmyadmin/.
  • I tried to setup wordpress and example.com redirects to http://ec2-xxxxxx.amazonaws.com/wp-admin/setup-config.php`

These are the things I have tried.

  • Added ServerName example.com in /etc/apache2/apache2.conf
  • This command sudo ufw allow in "Apache Full"
  • I do not have .htaccess in my /var/www/html folder.

Is it a Cloudfront or an Apache issue? This is my first rodeo with AWS and Apache and trying to learn how it works.

Solutions that seem out of scope:

  • https://serverfault.com/questions/685654/apache-server-config-redirect-from-ip-to-domain-name-ec2
  • Or anything that includes creating .htaccess at the root directory as I feel that would create an endless loop.

I can provide more information, if required.

Update:

  • Removed A and AAAA record from route53. Doesn't work.
  • Also, added ServerName example.com to /etc/apache2/sites-enabled/000-default.conf
  • Also, visiting random-id.cloudfront.net does the same redirection.
  • However, visiting elastic-IP does not do any redirection.
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If I correctly understand your setup, probably you need CNAME instead of A record in Route53

over 4 years ago · Santiago Trujillo Report

0

Traced the issue to HTTP_HOST being the ec2 public DNS received by the server. So, if I visited example.com/index.php and the code were supposed to redirect to example.com/index2.php it would instead redirect to ec.xxxxxx.amazonaws.com/index2.php because HTTP_HOST = ec.xxxxxx.amazonaws.com.

Fixed by updating CloudFront Distribution's behavior to forward Host value.

So, if I visit example.com the host value would be example.com

And if I visit id.cloudfront.net then host value would be id.cloudfront.net.

enter image description here

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!