DNS check + NGINX conf + Redirect

Hi, I already tried to search a lot but, I admit, I’m stuck. So I would like to check with you what I have and what I want to achieve:

  • 1 droplet
  • 2 domains (and so 2 websites)

$ORIGIN $TTL 1800 1800 IN A ( A record @ => 1800 IN A (A record test => 1800 IN A (A record www => NS & Co. records ok …

Question: “www” and “test” should be A records or CNAME records?

Then, server side, with NGINX:


server {
        listen 80;

        root /var/xxxxxx/;

        index index.php;



It works. Basic stuff right?

I want to redirect www to non-www

Again I searched and I found it is well covered and documented. So I followed and tried:

server {
        listen 80;

        root /var/xxxxxx/;

        index index.php;


        return 301 $scheme://$request_uri;

I got the following message:

“Page is not working” “ redirected you too many times ERR_TOO_MANY_REDIRECTS”

2 questions:

server_name; or server_name; or server_name;

And why I got this error.

When I play around even if I get the error if I do “curl -I” I got the following output:

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 17 Apr 2016 08:52:47 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive

But as soon as I hit the browser I receive the error…

Can you please help me to solve this. Thank you.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

So I found something with the help of this (one more) great resource.

I created a /etc/nginx/conf.d/redirect.conf and put:

server {
    return 301 $scheme://$request_uri;

Then on site available for


I hope it will help someone.

At least even if it works, can you confirm this is the right way…

Thank you