Report this

What is the reason for this report?

adding www to my domain at nginx server

Posted on January 21, 2014
FMCB

By FMCB

Hi.

I have been trying to add www to my domain like this:

from this:

http://domain.com

to this:

http://www.domain.com

I was following this article here: https://www.digitalocean.com/community/articles/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx

but ended up with no result. I believe it is something related to either ect/nginx/nginx.config or my domain file in sites-available…

There is one question I also want to ask, if the domain re-directed from http://domain.com to http://www.domain.com, would that be considered an extra http request. is there a way how to avoid extra requests?

any idea how that can go correct??

Thanks



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.

Look at here:

https://www.digitalocean.com/community/questions/configuring-multiple-domains-and-subdomains-dns-nginx-issues-abound

According to this link the solution is:

server {  
    server_name  domain1.com;  
    rewrite ^(.*) http://www.domain1.com$1 permanent;  
}  

server {  
        listen 80 default_server;  
        listen [::]:80 default_server ipv6only=on;  

        root /home/user/www/domain1;  
        index index.php index.html index.htm;  

        server_name www.domain1.com;  

        include hhvm.conf;  

} 

Oh, wait. Do you mean you really want a redirect, such that if a visitor types in ‘domain.com’, they will be redirected to ‘www.domain.com’? My response doesn’t help with that, it only enables the server to handle the ‘www’ form (or both forms, depending on which version you use).

Thanks @matt. <br> <br>I’ve already added www to my DNS. <br> <br>if I added www to the domain in the etc/nginx/sites-available/mydomain, not at nginx.conf in the nginx root folder. <br> <br>That works, but counted as an extra request. so an empty page takes 2 requests, which is a bad practice. <br> <br>I believe there a way how to do that, but not sure yet how!! <br> <br>regards

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.