Report this

What is the reason for this report?

Redirecting non-www to www in Nginx

Posted on July 13, 2014

I have successfully installed LEMP stack in Ubuntu 14 and running a phpBB forum. But the problem is that when I enter www.mydomain.com it shows a network error. Somebody please help me.



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!

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.

Edit your virtualhost file and replace yourdomain.com with www.yourdomain.com and add this at the top:

server {
    listen 80;
    server_name yourdomain.com;

    return 301 http://www.yourdomain.com$request_uri;
}

Restart nginx:

sudo service nginx restart

Finally, add a CNAME record with the name of “www” and the hostname of “@”.

I followed your guideline. But still it is not redirecting. Do I need to wait few hours for adding CNAME to take effect?

P.S.: vhost config: http://tny.cz/8fa87c05

Is this a PTR records issue? I set it to the same as hostname.

$hostname phpBB

Do I need to set PTR records to something different from above?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.