域名调整-SEO优化

===============================================

 2019/3/31_第1次修改                       ccb_warlock

 

===============================================

搜索引擎SEO优化是指通过一些手段,提高网站的权重(排名)。下面记录我收集的一些方法。

 


一、域名解析调整

为了配合用户习惯,之前调整了不带www的域名访问支持。

后来了解了SEO才知道,在搜索引擎看来,带www和不带www是2个不同的网站,如果不做强制跳转,搜索引擎会将这2个网站看成内容一致的的网站,从而导致权重被降低。而SEO优化可以提高网站的权重,这样有利于搜索引擎的排名。

 

前提:

1. 以www.abc.cn为例;

2. 以nginx作为反代服务器;

3. 反代目标地址:192.168.1.1;

 

调整前

server {
    listen 80;
    server_name www.abc.cn abc.cn;
    access_log off;
    error_log off;
    
    # 其他解析省略

    location / {
        rewrite ^(.*)$  https://$host$1 permanent;
    }
}

server {
    listen 443  ssl;
    server_name www.abc.cn abc.cn;    
    access_log off;
    error_log off;
    
    # ssl配置省略
    
    # 其他解析省略
    
    location / {
        proxy_pass http://192.168.1.1;
        
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
    }
}

调整后

思路:将abc.cn的解析单独拿出来。

假设:

  • 设计将http://abc.cn跳转到http://www.abc.cn
  • 设计将https://abc.cn跳转到https://www.abc.cn
server {
    listen      80; 
    server_name www.abc.cn;
    access_log  off;
    error_log   off;

    # 其他解析省略

    location / {
        rewrite ^(.*)$ https://$host$1 permanent;
    }
}

server {
    listen      443 ssl;
    server_name www.abc.cn;
    access_log  off;
    error_log   off;

    # ssl配置省略
    
    # 其他解析省略
    
    location / {
        proxy_pass http://192.168.1.1;
        
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
    }
}

server {
    listen      80;
    server_name abc.cn;
    access_log  off;
    error_log   off;

    location / {
        rewrite ^/(.*) http://www.abc.cn$request_uri? permanent;
    }
}

server {
    listen      443 ssl;
    server_name abc.cn;
    access_log  off;
    error_log   off;

    # ssl配置省略

    location / {
        rewrite ^/(.*) https://www.abc.cn$request_uri? permanent;
    }
}

 

猜你喜欢

转载自www.cnblogs.com/straycats/p/10634047.html
今日推荐