1

I'm trying to test out a new website before replacing the original one, since I don't want to impact users.

I have an existing website at say example.com and am working on a separate WordPress site to replace it when ready. To test things during this intermediate stage, that's hosted at example.net.

To keep things fast, we're using nginx instead of apache.

Inside my nginx.conf, I've got:

server {
  listen 80;
  server_name example.net www.example.net;
  # etc: location blocks that talk to wordpress and php
}

I've got this running on an EC2 instance, sitting behind a load-balancer.

The Issues:

If I run curl -vk load-balancer-dns.com, it includes: < HTTP/1.1 301 Moved Permanently, and < Location: http://example.net

Issue 1) I don't want this to create 301 to example.net, because sometime soon I'm going to change this to example.com when I'm ready to switch over.

Since the server_block mentioned above is the only server block, I assumed it was the default and that I didn't need to put in the server_name directive.

Issue 2) However, removing server_name example.net www.example.net (and restarting nginx so changes take effect), I get Too Many Redirects.

I can't figure out where the redirects are coming from - there are no rewrite, no permanent and no 301s in my nginx.conf.

Not trying to ask 2 questions at once, but I feel like solving one will help solve the other, and also trying to avoid an XY issue. Also, not sure if WordPress is relevant.

  • Try running the same curl command. – Michael Hampton Oct 24 '18 at 20:45
  • The redirects most likely come from the load balancer. – Tero Kilkanen Oct 24 '18 at 21:12
  • @MichaelHampton Running the same curl command on what? If I run curl -vk load-balancer-dns.com I get the redirect; if I run curl example.net, it returns the page correctly. – dwanderson Oct 24 '18 at 22:27
  • @TeroKilkanen - Shouldn't the load-balancer just be forwarding traffic to the instance, which then should handle serving the webpage in the default server block? The load-balancer shouldn't need to know anything about the domain name I'm actually trying to visit, should it? I could set hello.world in my /etc/hosts and point it at the load-balancer, and I would expect the page to load correctly, without redirecting. That's what happens with other sites, at least. – dwanderson Oct 24 '18 at 22:29
  • The redirects could also come from the CMS. For example, WordPress has the site URL in configuration, and it can do a redirect to that domain if the current HTTP Host header doesn't match the requested host. – Tero Kilkanen Oct 25 '18 at 22:40

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.