nginx配置不带www跳转带www的https链接


为了集中权重,把 haoyongba.com 和 www.haoyongba.com 合并到一个server上去,使用301永久重定向。 然后将 https://haoyongba.com转到 https://www.haoyongba.com 去。不过要在配置文件的 server https://www.haoyongba.com 上配置 default_server ssl;。 301永久重定向,这样可以把搜索引擎的权重全部集中到https://www.haoyongba.com上。 

server {
    listen       80;
    server_name haoyongba.com www.haoyongba.com;
    return 301 https://www.haoyongba.com/$request_uri;
}
server {
    listen 443;
    server_name souwp.cn;
    return 301 https://www.haoyongba.com/$request_uri;
}
server {
    listen 443 default_server ssl;
    server_name  www.haoyongba.com;
    ssl on;
    ssl_certificate 1_www.haoyongba.com_bundle.crt;
    ssl_certificate_key 2_www.haoyongba.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    root         /var/www/haoyongba;
    include /etc/nginx/default.d/*.conf;
    error_page 404 /404.html;
        location = /40x.html {
    }
 
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }