防止域名权重被分散的nginx 配置

24 min read
server
    {
        server_name www.test.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /alidata/www/test.com/public;

		listen 443 ssl;
  		ssl_certificate /usr/local/nginx/conf/ssl/test.com/full_chain.pem;
  		ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/private.key;

        include rewrite/laravel.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }


		location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_param PHP_ADMIN_VALUE 	"open_basedir=$document_root/:/alidata/www/test.com/:/tmp/:/proc/";
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /alidata/log/nginx/test.com.log;
    }

    server {
        listen 80;
        server_name test.com www.test.com;
        return 301 https://www.test.com$request_uri;
    }

    server {
        listen 443 ssl;
        server_name test.com;
        ssl_certificate /usr/local/nginx/conf/ssl/test.com/full_chain.pem;
        ssl_certificate_key /usr/local/nginx/conf/ssl/test.com/private.key;
        return 301 https://www.test.com$request_uri;
    }

1、带www的域名没有排名,而不带www却有排名,或正好相反

2、site:test.comsite:www.test.com的索引量差别巨大

3、若我们网站中添加了统计,会发现一些其他的域名解析到了自己的网站,也就是访问非*.test.com域名,也访问到了test.com的内容