以下是nginx的相关配置

#server1 http://example.com
server {
    listen       80;
    server_name  example.com;
    return 301 http://www.example.com$request_uri;
}

#server2 http://www.example.com
server {
    listen       80;
    server_name  www.example.com;
    return 301 https://$server_name$request_uri;
}

#server3 https://example.com
server {
    listen 443 ssl http2;
    server_name example.com;
    ssl_certificate 0000000_example.com.pem;
    ssl_certificate_key 0000000_example.com.key;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_protocols  TLSv1.2 TLSv1.3;
    return 301 https://www.example.com$request_uri;
}

#server4 https://www.example.com
server {
    listen 443 ssl ;
    server_name www.example.com;
    ssl_certificate 0000000_example.com.pem;
    ssl_certificate_key 0000000_example.com.key;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_protocols  TLSv1.2 TLSv1.3;
    location / {
        root   /usr/share/nginx/html;
        index index.html index.htm;
    }    
}

FAQs

Q:为什么要重定向多次?而不直接重定向到 https://www.example.com

A:为了降低出错后的维护成本,当ssl出现问题时,只需修改一个server(server2)即可以http的方式访问,从而恢复正常工作。

Q:这样做对SEO有影响吗?

A:鄙人才疏学浅,请自行查阅资料了解。目前看来,使用Google可以搜索到本站的内容,但是某度却不行。

标签: none

添加新评论