Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda