Force sub domain to www

Mr. Jinx

Verified User
Joined
May 5, 2006
Messages
61
I noticed that google is indexing my sites with different sub domains.
For example, main site is www.site.com.
However, it is also accesible with mail.site.com and ftp.site.com.
Google will index this and mark it as duplicate content, which is bad for your rankings.

What can I do with nginx configfiles to prevent this?
 
That is a very good explanation, but I don't see an easy way to use this with DA in a good way.

Right now I am using this:
Code:
if ($host != 'www.site.com') {
              rewrite  ^/(.*)$  http://www.site.com/$1 redirect;
       }

...but "This is a wrong, cumbersome, and ineffective way", they say.
What would be an effective way? Defining different server rules seems to be not possible with the current configs.
 
Do you use NGINX as a stand-alone web-server? Or you use it as a reverse proxy with apache? Do you need these settings on all domains? Or only on one specific?
 
Nginx as a stand-alone server.
I would like to apply this to all domains. The main reason is to prevent google from spidering the wrong/duplicate domains.
 
Please try the following:

1. Copy templates

/usr/local/directadmin/data/templates/nginx_server.conf
/usr/local/directadmin/data/templates/nginx_server_secure.conf


to /usr/local/directadmin/data/templates/custom/
(create the directory if it does not exist)


2. Modify

/usr/local/directadmin/data/templates/custom/nginx_server.conf

and add the following at the bottom:

Code:
server{
        listen |IP|:|PORT_80|;
        |MULTI_IP|

        server_name  ftp.|DOMAIN| mail.|DOMAIN| pop.|DOMAIN| smtp.|DOMAIN|;
        return 301 http://www.|DOMAIN|$request_uri;
}


/usr/local/directadmin/data/templates/custom/nginx_server_secure.conf

Code:
server{
        listen |IP|:|PORT_443| ssl;
        |MULTI_IP|

        server_name  ftp.|DOMAIN| mail.|DOMAIN| pop.|DOMAIN| smtp.|DOMAIN|;

        ssl on;
        ssl_certificate |CERT|;
        ssl_certificate_key |KEY|;

        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 5m;

        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        return 301 https://www.|DOMAIN|$request_uri;
}

3. rewrite virtual hosts

Code:
[COLOR=#000000][FONT=courier new]echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue[/FONT][/COLOR]

p.s. You could use asterix (which is allowed http://nginx.org/en/docs/http/server_names.html ) in a server name

Code:
server_name  *.|DOMAIN|;

instead of listing names

Code:
server_name  ftp.|DOMAIN| mail.|DOMAIN| pop.|DOMAIN| smtp.|DOMAIN|;


but this will break your sub-domains (sub1.domain.com, sub2.domain.com, etc), as they come in NGINX.conf after main parent www.domain.com.

p.p.s Use robots.txt
 
Back
Top